配置文件的读写

1  Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
2  config.AppSettings.Settings.Remove("sqlStr");
3  config.AppSettings.Settings.Add("sqlStr", sqlStr);
4  //一定要记得保存,写不带参数的config.Save()也可以 
5  config.Save(ConfigurationSaveMode.Modified);
6  //刷新,否则程序读取的还是之前的值(可能已装入内存)
7  System.Configuration.ConfigurationManager.RefreshSection("appSettings");
View Code

 

1 string value = config.AppSettings.Settings[key].Value;
View Code

 

posted on 2016-08-01 11:16  Joey.ZJ  阅读(110)  评论(0编辑  收藏  举报