C# update configuration file
2020-12-27 15:27
标签:name system static 图片 user settings info val update C# update configuration file 标签:name system static 图片 user settings info val update 原文地址:https://www.cnblogs.com/Fred1987/p/13347154.htmlusing System.Configuration;
static void Main(string[] args)
{
UpdateConfigAppSettings();
ReadConfig();
Console.ReadLine();
}
static void UpdateConfigAppSettings()
{
Configuration cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
cfg.AppSettings.Settings["UserName"].Value = "Fred";
cfg.AppSettings.Settings["UserPwd"].Value = "FredPwd";
cfg.AppSettings.Settings["IsRemembered"].Value = "True";
cfg.Save(ConfigurationSaveMode.Modified, true);
ConfigurationManager.RefreshSection("appsettings");
}
static void ReadConfig()
{
Console.WriteLine($"{ConfigurationManager.AppSettings["UserName"].ToString()}\n" +
$"{ConfigurationManager.AppSettings["UserPwd"].ToString()}\n" +
$"{ConfigurationManager.AppSettings["IsRemembered"].ToString()}");
}
文章标题:C# update configuration file
文章链接:http://soscw.com/index.php/essay/38615.html