如何在c#winforms中的app.config文件上动态更新应用程序设置键值。 键,值列在下面
<appSettings>
<add key="logPath" value="C:\EventLogs" />
<add key="isScreenCaptureMode" value="false" />
<add key="isStartOnSysStartUp" value="false" />
</appSettings>
答案 0 :(得分:3)
Configuration configuration = ConfigurationManager.
OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
configuration.AppSettings.Settings["logPath"].Value = DateTime.Now.ToString("yyyy-MM-dd");
configuration.Save();
ConfigurationManager.RefreshSection("appSettings");
答案 1 :(得分:2)
我相信这就是你要找的东西:
using System.Configuration;
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["isScreenCaptureMode"].Value = "true";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");