开发者

How to make ConfigurationManager read a config file other than app.config?

开发者 https://www.devze.com 2022-12-29 14:13 出处:网络
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 confi

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);


Or like this:

var fileMap = new ConfigurationFileMap(configFilePath);
Configuration config = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);

But you still will have a problem with custom configuration sections.

0

精彩评论

暂无评论...
验证码 换一张
取 消