开发者

Read config files in a WPF project

开发者 https://www.devze.com 2023-03-03 17:43 出处:网络
I have开发者_C百科 a WPF application. This application should read a web.config file (from a asp.net webforms project) and a myCompany.config file.

I have开发者_C百科 a WPF application. This application should read a web.config file (from a asp.net webforms project) and a myCompany.config file. How can I do this? Is there a easy way to handle this?

Any help would be appreciated.

thanks!


Sounds like you need to use configurationmanager

http://msdn.microsoft.com/en-us/library/aa719887%28v=vs.71%29.aspx

http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx


So if I understood correctly, you want to read config files which are stored in a specific path?

Here is the trick:

Configuration _userConfig;
String configFilePath = "Your path here";

//Getting the user configuration object:
//Mapping the appropriate path:
ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
configFileMap.ExeConfigFilename = configFilePath;
_userConfig = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);

And there you go, _userConfig will contain the details in the path you specified :)

0

精彩评论

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