C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Reading value from App.Config C# Windows Application - Winforms


Posted Date: 08 Oct 2008    Resource Type: Code Snippets    Category: General

Posted By: Mathew Philip       Member Level: Gold
Rating:     Points: 10



We may require small or medium changes in our code to run it in different machines and differnt configurations, Recompailing and Regenerating .exe files / dlls are a not a good practice. So we are using configuration files or settings files. Web.config is an example of such type file in web application. In Winforms or Windows application we need to use App.Config to achive the goal.

Here is an example to store and retreive the value from App.Config

Initially add an App.Config file to your project then set the values like following within the < appSettings > < /appSettings > block


< appSettings >
< add key="Name" value="Mathew Philip"/> < /appSettings >


In the code behind you should import the following namespace



using System.Configuration;



Then retreive the value from the App.Config by the following code


string name = Convert.ToString(ConfigurationSettings.
AppSettings["Name"])


So that you can simply edit the XML in the App.Config and change your values without reconstructing the Exe file or Dll file. You can encript and store the contents if you want more security.




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Winforms  .  Retreive Value  .  Configuartion  .  App.config Example  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to generate SecurityBot Text using C#
Previous Resource: Connection With The MS-Access DataBase
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

UK Conference calling Company

Contact Us    Privacy Policy    Terms Of Use