首页 > 移动平台 > 详细

配置文件(App.config)的读写操作

时间:2016-08-09 13:26:41      阅读:243      评论:0      收藏:0      [点我收藏+]
  1. 修改App.config文件
 App.config文件编译生成后,产生两个文件(*.exe.config和*.vshost.exe.config) ,第一个文件为项目实际使用的配置文件,在程序运行中所做的更改都将被保存于此;第二个文件其实为原代码中“App.config”的同步文件,在程序运行中不会发生更改。
 1        string appPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
 2             string configFile = System.IO.Path.Combine(appPath, "CmdDisPro.exe.config");   
 3             ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
 4             configFileMap.ExeConfigFilename = configFile;
 5             System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None, true);
 6 
 7             //基础设置
 8             config.AppSettings.Settings["SysName"].Value = ivmBasic.SysteName;
 9             config.AppSettings.Settings["OrganName"].Value = ivmBasic.CurrentUnit;
10             config.AppSettings.Settings["AlarmInitializationSpan"].Value = ivmBasic.InitAlarmTimespan;
11             config.AppSettings.Settings["AlarmSecondsTimeout"].Value = ivmBasic.AcceptAlarmTime;
12 
13             config.Save(ConfigurationSaveMode.Modified);
14             ConfigurationManager.RefreshSection("appSettings");

2.读取App.config文件

HttpUrl = ConfigurationManager.AppSettings["HttpServiceUrl"];

  

 

配置文件(App.config)的读写操作

原文:http://www.cnblogs.com/tianyuan05/p/5752788.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!