1

I've got two projects under the same solution. I use one project to update the app.config file of the second project. I manage to read the values I need, by using the GetSection method and the ClientSettingsSection class, but I can't find how to update those values.

Guy
  • 325
  • 1
  • 3
  • 18

2 Answers2

2
ConfigurationManager.RefreshSection(sectionName);

Do you mean this?

genesis
  • 50,477
  • 20
  • 96
  • 125
  • I'm trying to modify a value that was entered in the second project's properties. I managed to get the property's value, but can't find out how to modify it. How does RefresSection help modify the property's value? – Guy Aug 07 '11 at 20:44
0

You can do something like this:

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Add("MyKey", "MyValue);
config.Save(ConfigurationSaveMode.Modified);

But the application configuration file is cached, so you need to call the ConfigurationManager.RefreshSection() method: http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.refreshsection.aspx

  • I'm trying to modify a key which isn't in the appSettings section, but in another section, that's why I used the GetSection method. Your code adds a key to the appSettings section. To be more precise, I'm trying to modify keys that were entered in the Properties of the second project. – Guy Aug 07 '11 at 20:40