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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
ConfigurationManager.RefreshSection(sectionName);
Do you mean this?
回答2:
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