// 文件路径 private static string ConfigPath = AppDomain.CurrentDomain.BaseDirectory + @"\XXX.config"; private static AppSettingsSection _sviewFrameSetting; public static string OnlineViewService = GetAppSettings("OnlineViewService"); /// <summary> /// 获取指定文件AppSettings /// </summary> private static void LoadAppSetting() { ExeConfigurationFileMap map = new ExeConfigurationFileMap(); map.ExeConfigFilename = ConfigPath ; Configuration _sviewFrameConfiguration = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None); //如果配置文件中不包括appSettings节,则抛出异常. if (_sviewFrameConfiguration.Sections["appSettings"] != null) { _sviewFrameSetting = _sviewFrameConfiguration.AppSettings; } } /// <summary> /// 获取配置信息 /// </summary> /// <param name="key"></param> /// <returns></returns> private static string GetAppSettings(string key) { if (_sviewFrameSetting == null) { LoadAppSetting(); } return _sviewFrameSetting.Settings[key].Value; }
标签:map,string,AppSettings,sviewFrameSetting,指定,private,获取,static From: https://www.cnblogs.com/anjingdian/p/17354769.html