c# - 使用 XMl 阅读器读取配置文件

标签 c# xml web-config drop-down-menu

我的 web.config 文件的 AppSettings 部分有一堆 key 。我想使用 XML 阅读器技术读取这些应用程序设置的键和值,并将它们填充到列表框中。

最佳答案

检索 webconfig 值的最佳方法是使用 System.Configuration.ConfigurationManager.AppSettings;

从 xml 阅读器中检索 webconfig 的值:

private void loadConfig()
        {

            XmlDocument xdoc = new XmlDocument();
            xdoc.Load( Server.MapPath("~/") + "web.config");
            XmlNode  xnodes = xdoc.SelectSingleNode ("/configuration/appSettings");

                foreach (XmlNode xnn in xnodes .ChildNodes)
                {
                    ListBox1.Items.Add(xnn.Attributes[0].Value  + " = " + xnn.Attributes[1].Value );
                }              

        }

引用:http://dotnetacademy.blogspot.com/2010/10/read-config-file-using-xml-reader.html

关于c# - 使用 XMl 阅读器读取配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3868179/

相关文章:

c# - MYSQL C# 获取剩余天数查询

c#这些音量变化代码/消息是什么

c# - Selectnodes 只获取第一个节点

json - 这些数据格式中哪种需要最少的带宽?

java - 解析类似结构的 XML 文件的单一实现

c# - LINQ - 在 IEnumerable 中选择第二个项目

c# - 使用 XmlWriter 附加到 XML 文件

java - 如何使用Azure Web应用程序的配置文件

azure - 如何在Azure App Service中配置多个虚拟应用程序?

asp.net - web.config、configSource 和 "The ' xxx' 元素未声明“警告