I've got开发者_StackOverflow 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.
ConfigurationManager.RefreshSection(sectionName);
Do you mean this?
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
精彩评论