access web.config using wpf
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
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"));
精彩评论