code_junkie

Loading custom configuration files

Nov 14th, 2011
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. private static XmlDocument loadConfigDocument()
  2. {
  3. XmlDocument doc = null;
  4. try
  5. {
  6. doc = new XmlDocument();
  7. doc.Load(getConfigFilePath());
  8. return doc;
  9. }
  10. catch (System.IO.FileNotFoundException e)
  11. {
  12. throw new Exception("No configuration file found.", e);
  13. return null;
  14. }
  15. catch (Exception ex)
  16. {
  17. return null;
  18. }
  19. }
  20.  
  21. // retrieve appSettings node
  22.  
  23. XmlNode node = doc.SelectSingleNode("//appSettings");
  24.  
  25. ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
  26. configMap.ExeConfigFilename = @"d:testjustAConfigFile.config.whateverYouLikeExtension";
  27. Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
Add Comment
Please, Sign In to add comment