0

Would anyone be so kind as to help me figure out how to open a web.config file from a wpf thick client. I have a wpf form (not a silverlight app) that I would like have the ability to browse to a directory ( c:\test\web.config ) and then load custom keys from the appSettings section of the selected web.config file. Example Bind a field within my form to Path=Version

Within the web.config file Version would be identified as:

<add key="Version" value="1.0 />

Thanks in advance

1 Answer 1

4

I usually prefer to use one of the ConfigurationManager methods like this one:

http://msdn.microsoft.com/en-us/library/ms224437.aspx

Or there is the old style Xml with XPath:

XmlDocument webConfig = new XmlDocument();
webConfig.Load(dllConfigFileName);
XmlNode someNode = webConfig.SelectSingleNode("//configuration/appSettings/add[@key='someKey']");

Or the newer LINQ to XML:

XDocument document = XDocument.Load(configFileFullName);
XElement configurationElement = document.Element("configuration");
XElement appSettingsElement = configurationElement.Element("appSettings");
List<XElement> configSettings = new List<XElement>(appSettingsElement.Descendants("add"));
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Russell. In digging through the site I also found this article while it applies to Win-Forms I have tested it and it is a viable solution adn does not require for the ddocument to be laoded as a regular xml document. stackoverflow.com/questions/1300423/…
I upped your answer by one for the tip on the XDocument class. I've done a little reading and that is the direction I've taken. Using Linq not only can I prop a colleciton but I can also parse out the specifics of each key!. Thanks again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.