Change App.Config File

Posted by in C# category on for Beginner level | Views : 12532 red flag

This article will explore the details related to change the App.Config file setting at runtime in Windows application.


Sometimes we require to change the settings related to App.Config file at runtime in the application. So, we require the AppSettings for changing the App.Config File

Pre-Requisite: User should know how to add the appSettings in the App.Config fie, so user should have basic idea to create the key and set the value for the key in the AppSetting node before changing the value at runtime.

Required references

We require following the references in the application to modify the App.Config File
1. System //This is the default reference
2. System.Configuration

All Set? Now change the Config File

After adding the details related to the References we can change the AppSetting section from the App.Config file
Now, add the namespace


Code to change the AppSetting section.

C# Code

//Create the object of the Class Configuration

Configuration objConfig= ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

//Key to Add in the App.Config file


// Now, we can save the configuration file.


// After saving the file we have to refresh the section



You will not see any changes in the App.Config file as it may be in the debug mode. So please release the application and make the changes you can see the change in the app.config file


This way you can manage the appSetting section of the App.Config file from the C# application at runtime.

Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: nikhil chauhan
Member Level: Bronze
Member Status: Member
Member Since: 11/25/2008 9:12:37 PM
Keep posting and Enjoy coding...

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)