C#读取App.config文件信息
1、app.config文件
2、根据Key获取值
string FilePaths = ConfigurationManager.AppSettings["FilePaths"];
注意:需要添加【System.Configuration.dll】引用
3、修改Key的值
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
cfac.AppSettings.Settings["MAC"].Value = string.Empty;
cfac.Save();Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
cfa.AppSettings.Settings["MAC"].Value = mac;
cfa.Save();
4、参考网址【https://blog.csdn.net/weixin_30425949/article/details/96756367】
5、读取指定文件下app.config文件
ExeConfigurationFileMap map = new ExeConfigurationFileMap();
map.ExeConfigFilename = @"F:\App1.config"; ;
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
string connstr = config.ConnectionStrings.ConnectionStrings["connStr"].ConnectionString;
MessageBox.Show(connstr);
string key = config.AppSettings.Settings["key"].Value;
MessageBox.Show(key);
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
