1

I have this statement, that's supposed to set the value of a key in my config:

ConfigurationManager.AppSettings["Volume"] = volumeNumSlider.Value.ToString();

But it does not save the value when I relaunch the application.

This is my app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <appSettings>
       <add key="Volume" value="7"/>
       <add key="Keyval" value="Z"/>
   </appSettings>
</configuration>
dvs
  • 97
  • 1
  • 8

1 Answers1

6

That will not update it, you have save the changes back to config file following way:

Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
configuration.AppSettings.Settings["Volume"].Value = volumeNumSlider.Value.ToString();
configuration.Save(ConfigurationSaveMode.Modified);

ConfigurationManager.RefreshSection("appSettings");
Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160