C# 读取 config 文件

ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = filePath;
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
AppSettingsSection appSettings = (AppSettingsSection)config.GetSection("appSettings");
KeyValueConfigurationCollection keyValues = appSettings.Settings;

Dictionary<string, string> items = new Dictionary<string, string>();
 foreach (string key in keyValues.AllKeys)
{
       items.Add(key, keyValues[key].Value);
}

return items;

 

注意 :  不要使用  var 对上面程序进行 变量声明

posted on 2012-02-19 23:41  多个马甲  阅读(515)  评论(0编辑  收藏  举报