Csharp/C#教程:如何在C#Winforms中的app.config中保存配置分享


如何在C#Winforms中的app.config中保存配置

有人能举例说明如何使用C#和WinForms在app.config中保存键/值吗?

ASP.NET中

 Configuration config = WebConfigurationManager.OpenWebConfiguration(null); AppSettingsSection app = config.AppSettings; app.Settings.Add("x", "this is X"); config.Save(ConfigurationSaveMode.Modified); 

WinForms中

 Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); AppSettingsSection app = config.AppSettings; app.Settings.Add("x", "this is X"); config.Save(ConfigurationSaveMode.Modified); 

我知道你特意要求WinForms解决方案,但这可能对其他人有所帮助。 对于.NET 4.0控制台应用程序,这些都不适用于我。 所以我使用了以下内容并且它有效:

 private static void UpdateSetting(string key, string value) { Configuration configuration = ConfigurationManager. OpenExeConfiguration(Assembly.GetExecutingAssembly().Location); configuration.AppSettings.Settings[key].Value = value; configuration.Save(); ConfigurationManager.RefreshSection("appSettings"); } 

这样的事情可能是: http : //geekswithblogs.net/akraus1/articles/64871.aspx

上述就是C#学习教程:如何在C#Winforms中的app.config中保存配置分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请点击右边联系管理员删除。

如若转载,请注明出处:https://www.ctvol.com/cdevelopment/957694.html

(0)
上一篇 2021年11月22日
下一篇 2021年11月22日

精彩推荐