如何在运行时修改我App.exe.config钥匙? [英] How to modify my App.exe.config keys at runtime?
问题描述
在我的app.config我有这个节
<的appSettings>
<添加键=用户ID值=的myuserid/>
//一些其它实施;添加键和GT; S
< /的appSettings>
通常我访问使用用户id的值= ConfigurationManager.AppSettings [用户ID]
如果我修改它使用 ConfigurationManager.AppSettings [用户ID] =东西
,该值不保存到文件中,下次我加载应用程序,它使用旧的价值。
我怎样才能改变一些的app.config键的值?
System.Configuration.Configuration配置= ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings [用户ID]值=的myuserid。
config.Save(ConfigurationSaveMode.Modified);
您可以阅读ConfigurationManager的<一个href="http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx">here
In my app.config I have this section
<appSettings>
<add key ="UserId" value ="myUserId"/>
// several other <add key>s
</appSettings>
Usually I access the values using userId = ConfigurationManager.AppSettings["UserId"]
If I modify it using ConfigurationManager.AppSettings["UserId"]=something
, the value is not saved to the file, and next time I load the application, it uses the old value.
How can I change the value of some app.config keys during runtime?
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["UserId"].Value = "myUserId";
config.Save(ConfigurationSaveMode.Modified);
You can read about ConfigurationManager here
这篇关于如何在运行时修改我App.exe.config钥匙?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!