标签:
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"];
标签:
原文地址:http://www.cnblogs.com/tianyuan05/p/5752788.html