I have a Windows Service written, and want to modify it's config file. I have an app in the same solution for this:
private ExeConfigurationFileMap map = new ExeConfigurationFileMap();
map.ExeConfigFilename = @"pathToMyWSConfigFile";
and then I do:
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
config.AppSettings.Settings.Add("ServerPath", "test replace ");
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
However this simply adds another value to the ServerPath key in config file, and I want to replace it, so that there is always only one value there. How can I do it?