简体   繁体   English

使用wpf访问web.config

[英]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. 谁能帮助我找出如何从WPF胖客户端打开web.config文件的人。 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. 我有一个wpf表单(不是Silverlight应用程序),我希望能够浏览到目录(c:\\ test \\ web.config),然后从选定的web.config文件的appSettings部分加载自定义键。 Example Bind a field within my form to Path=Version 示例将表单中的字段绑定到Path = Version

Within the web.config file Version would be identified as: 在web.config文件中,版本将标识为:

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

Thanks in advance 提前致谢

I usually prefer to use one of the ConfigurationManager methods like this one: 我通常更喜欢使用类似以下一种ConfigurationManager方法:

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

Or there is the old style Xml with XPath: 还是有带有XPath的旧样式Xml:

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

Or the newer LINQ to XML: 或更新的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"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM