【发布时间】:2013-04-11 12:29:07
【问题描述】:
以下是我用来更新或更改 app.config 中 appsetting 中的值的代码
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["userName"].Value = username;
config.AppSettings.Settings["pwd"].Value = pwd;
config.Save(ConfigurationSaveMode.Modified, true);
ConfigurationManager.RefreshSection("appSettings");
我正在使用上面的代码在运行时更改或更新 appsetting 部分中的设置,并希望这些更改保持不变,以便在我运行应用程序时它应该从 appsettings 中选择新值,但在这里它不会发生,所以更改当我再次重新启动我的应用程序时,在运行时制作和保存的内容不会持续存在,它具有旧的默认设置。我还检查了 bin/debug 中的 app.config,但它在 appsettings 中也有旧值。我参考了各种博客并在这里发帖作为参考,但它得到了与上面相同的代码,但它没有保留设置。have referred this post
【问题讨论】:
-
您在哪里检查新值?在代码或 app.config 中?
-
在 App.config 中,当用户提供新的用户名和密码时,我的应用程序应该覆盖在 aspp.config 中的 appsettings 中设置的默认用户名和密码,并且下次启动时我想要最后更新的用户名和密码因此我正在寻找一种方法,以便我可以保留对 app.config 中的 appsettings 值所做的任何更改。但不知何故,上面的代码不会在 appsettings 中保存新值。
标签: c# wpf c#-4.0 app-config