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 :)
精彩评论