You can use the ConfigurationManager class.
There are many examples from the link above or in this article , which also contains a brief example. You need to add the link before System.Configuration , and basically you access and save the file as follows:
// Open App.Config of executable System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); // Do stuff // Save the configuration file. config.Save(ConfigurationSaveMode.Modified);
To force your program to update data immediately, you need to update the section using the ConfigurationManager.RefreshSection method
And it is important to note this thread , for those who say that it does not work in debug mode:
If you use the code from the debugger (in VS) than your code really changes YourAssemblyName.vshost.exe.Config If you run YourAssemblyName.exe directly from the bin \ debug folder. YourAssemblyName.exe.Config will change
Chris source share