This article will explore the details related to change the App.Config file setting at runtime in Windows application.
IntroductionSometimes 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 referencesWe require following the references in the application to modify the App.Config File
1. System //This is the default reference
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.
//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.
About the Author