I am trying to update the appconfig file on run time with the following code. I do not get an error but it does not update my config file.
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
string oldValue = config.AppSettings.Settings["Username"].Value;
config.AppSettings.Settings["Username"].Value = "NewValue";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
Adding the config.AppSettings.SectionInformation.ForceSave = true; will do the trick. You should then look in YourProject.vshost.exe.config when debugging as Justin said. The modifications are saved there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With