如何使ConfigurationManager的阅读比其他的app.config配置文件? [英] How to make ConfigurationManager read a config file other than app.config?
本文介绍了如何使ConfigurationManager的阅读比其他的app.config配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要解析位于另一个项目的配置文件。我知道,ConfigurationManager的默认读取app.config文件,但如何让它读取特定的配置文件?
解决方案
//创建一个filemap指的配置文件。
ExeConfigurationFileMap fileMap =新ExeConfigurationFileMap();
fileMap.ExeConfigFilename = configFilePath;
//获取配置文件。
配置配置= ConfigurationManager.OpenMappedExeConfiguration(fileMap,ConfigurationUserLevel.None);
I need to parse a config file that is situated in another project. I know that ConfigurationManager reads the app.config file by default, but how to make it read that particular config file?
解决方案
// Create a filemap refering the config file.
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = configFilePath;
// Retrieve the config file.
Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
这篇关于如何使ConfigurationManager的阅读比其他的app.config配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文