How to update app settings key, value dynamically on app.config file in c# winforms. Key,value are listed below
<appSettings>
<add key="logPath" value="C:\EventLogs" />
<add key="isScreenCaptureMode" value="false" />
<add key="isStartOnSysStartUp" value="false" />
</appSettings>
The sample source code allows you to change the key and value pair. There is no need to open web. config file. The application also allows you to update and delete the key/value pair.
The App. config that holds all the required configuration for a GWM based solution to work is stored inside the SAP Service Reference folder under the project file. For running a GWM based solution you need to either have only one App.
App. Config is an XML file that is used as a configuration file for your application. In other words, you store inside it any setting that you may want to change without having to change code (and recompiling). It is often used to store connection strings.
Configuration configuration = ConfigurationManager.
OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
configuration.AppSettings.Settings["logPath"].Value = DateTime.Now.ToString("yyyy-MM-dd");
configuration.Save();
ConfigurationManager.RefreshSection("appSettings");
I believe this is what you are looking for:
using System.Configuration;
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["isScreenCaptureMode"].Value = "true";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With