C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Training   ASP.NET Web Hosting    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

Play Silverlight Games or Submit your Silverlight applications and earn 90% AdSense revenue.

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




Resources » Code Snippets » General »

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


Posted Date: 08 Oct 2008    Resource Type: Code Snippets    Category: General
Author: Mathew PhilipMember 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

Author: Atul Vishwakarma    23 Jun 2009Member Level: Bronze   Points : 1
Goog yaar,
but please provide complete example using C# and SQL with app.config.


Author: Vijayaragavan.R    23 Jun 2009Member Level: Bronze   Points : 0
This is nice one,

Please give me an example of read an value from it.



Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Winforms  .  Retreive Value  .  Configuartion  .  Best  .  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

About Us    Contact Us    Privacy Policy    Terms Of Use