.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Articles >> Windows Application >> Post New Resource Bookmark and Share   

 Subscribe to Articles

How to edit Application Configuration - appSettings section?

Posted By:Jean Paul       Posted Date: January 13, 2011    Points: 75    Category: Windows Application    URL: http://www.dotnetspark.com  

How to edit Application Configuration - appSettings section?


The application configuration file provides flexibility in reading application settings.  But once in a while it is needed to change the settings programmatically.  We can see how it is made possible.

Step 1: Create new Windows Forms application

Create a new windows forms application and add a config file into it.

Replace the content of app.config with following:


Add two buttons to the form named read and write.

On the read button click add the following code:

string value = ConfigurationManager.AppSettings["font"];
Step 2: Add reference to System.Configuration

The System.Configuration namespace is required for getting the required functionality.

Step 3: Add code to edit config

Now we are ready to write the appSettings editing code.  Click on the write button from the form and

add the following code to it.

System.Configuration.Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

configuration.AppSettings.Settings.Add("font", "Calibri");



For editing an existing appSettings key - we have deleted and added the key.

Run the Application

Execute the application and you can test the editing of configuration using the read/write buttons.

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend