If I have in the web.config
file of web application :
<appSettings>
<add key="DD" value="567_Access"/>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>
I know how to read the data in appSettings sections like this :
string accessD = ConfigurationManager.AppSettings["DD"];
But I want to know how to Modify (Set) the value of a key in appSettings
Through the code ?
(I want through a specific check to this value to stop the application under some circumstances)
System.Configuration.ExeConfigurationFileMap configFile = new System.Configuration.ExeConfigurationFileMap();
configFile.ExeConfigFilename = "ConsoleTester.exe.config"; //name of your config file, can be from your app or external
System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(configFile, System.Configuration.ConfigurationUserLevel.None);
System.Configuration.KeyValueConfigurationCollection settings = config.AppSettings.Settings;
settings["DD"].Value = "007_Access";
config.Save();
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments