Created
December 1, 2014 10:56
-
-
Save johnbabb/a5daa4d10742b50a18f8 to your computer and use it in GitHub Desktop.
Edit Config - Replace Key Value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void SaveConfig(string key, string value) | |
{ | |
var config = ConfigurationManager.OpenExeConfiguration(Path.Combine(AssemblyDirectory, Assembly.GetExecutingAssembly().ManifestModule.Name)); | |
var applicationSectionGroup = config.GetSectionGroup("applicationSettings"); | |
var applicationConfigSection = applicationSectionGroup.Sections["AsyncLogging.Properties.Settings"]; | |
var clientSection = (ClientSettingsSection)applicationConfigSection; | |
var applicationSetting = clientSection.Settings.Get(key); | |
applicationSetting.Value.ValueXml.InnerText = value; | |
applicationConfigSection.SectionInformation.ForceSave = true; | |
config.Save(); | |
config.Save(ConfigurationSaveMode.Modified); | |
ConfigurationManager.RefreshSection("applicationSettings/AsyncLogging.Properties.Settings"); | |
ConfigurationManager.RefreshSection("AppSettings"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment