使用 XML 阅读器读取配置文件 [英] Read config file using XMl reader

查看:35
本文介绍了使用 XML 阅读器读取配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a bunch of key in AppSettings section of my web.config file. I want to read the key and values of those app settings using XML reader technique and populate them in the list box.

推荐答案

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

The best way is to retrive webconfig values is to use System.Configuration.ConfigurationManager.AppSettings;

从 xml reader 检索 webconfig 的值:

To retrive values of webconfig from xml reader:

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

这篇关于使用 XML 阅读器读取配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆