需要操作 App.Config中的AppSettings,所有示例代码如下:
const string key = "EFConnectionString";
//获取Configuration对象
Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
//根据KEY读取值
string efConnStr = config.AppSettings.Settings[key].Value;
//根据KEY写入Value
config.AppSettings.Settings[key].Value = encConnStr;
////增加元素
//config.AppSettings.Settings.Add(key, "value");
////删除元素
//config.AppSettings.Settings.Remove(key);
//一定要记得保存,不带参数的config.Save()以
config.Save(ConfigurationSaveMode.Modified);
//刷新设置,让程序应用最新的值
ConfigurationManager.RefreshSection("appSettings");
达叔傻乐(darwin.zuo@163.com)
网友评论