Change the value in app.config file dynamically

.net, c#

Solution

This code works for me:

    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 
    config.AppSettings.Settings["test"].Value = "blah";       
    config.Save(ConfigurationSaveMode.Modified);
    ConfigurationManager.RefreshSection("appSettings");

Note: it doesn't update the solution item 'app.config', but the '.exe.config' one in the bin/ folder if you run it with F5.

Problem

I want to modify a value in appSetting section in app.config. So i wrote, ``` Console.WriteLine(ConfigurationManager.AppSettings["name"]); Console.Read(); Configuration config=ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.AppSettings.Settings["name"].Value = "raja"; config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); Console.WriteLine(ConfigurationManager.AppSettings["name"]); Console.Read(); ``` after the execution of above code, i verified the app.config whether the value of "name" element has been changed or not. but no change. what is the wrong with my code? or is there any other way to do this?

Original source

Related problems