I have the following code to add a new key value pair to app.config file appSettings section.
Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Add("Hello", "World");
string name = config.AppSettings.Settings["Hello"].Value;
config.Save(ConfigurationSaveMode.Modified);
System.Configuration.ConfigurationManager.RefreshSection("appSettings");
System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\xxx\xml.txt");
file.WriteLine(name);
file.Close();
When I run the application and open the app.config file, nothing changed. However, the string World
is written on the xml.txt which means this key value pair did exist.