How to update a key pair of an application parameter value dynamically in an app.config file in C # winforms

How to update application settings key, dynamically add app.config file in winforms C #. Key value listed below

<appSettings> <add key="logPath" value="C:\EventLogs" /> <add key="isScreenCaptureMode" value="false" /> <add key="isStartOnSysStartUp" value="false" /> </appSettings> 
+5
source share
2 answers
 Configuration configuration = ConfigurationManager. OpenExeConfiguration(Assembly.GetExecutingAssembly().Location); configuration.AppSettings.Settings["logPath"].Value = DateTime.Now.ToString("yyyy-MM-dd"); configuration.Save(); ConfigurationManager.RefreshSection("appSettings"); 
+3
source

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"); 
+2
source

Source: https://habr.com/ru/post/1276104/


All Articles