Skip to content

Instantly share code, notes, and snippets.

@johnbabb
Created December 1, 2014 10:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnbabb/a5daa4d10742b50a18f8 to your computer and use it in GitHub Desktop.
Save johnbabb/a5daa4d10742b50a18f8 to your computer and use it in GitHub Desktop.
Edit Config - Replace Key Value
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