读取config文件中的键值

新建个config文件

<?xml version="1.0" encoding="utf-8"?>
<!--
注意: 除了手动编辑此文件以外,您还可以使用 Web 管理工具来
配置应用程序的设置。
可以使用 Visual Studio 中的“网站”->“Asp.Net 配置”选项。
设置和注释的完整列表在 machine.config.comments 中,
该文件通常位于
\Windows\Microsoft.Net\Framework\v2.x\Config 中
-->
<configuration>
<appSettings>
<!--需要抛送的行-->
<add key="useRow" value="7"/>
<!--需要抛送的行-->
<add key="useRow" value="8"/>
<!--需要抛送的行-->
<add key="useRow" value="9"/>
<!--需要抛送的行 -->
<add key="useRow" value="10"/>
<!--需要抛送的行-->
<add key="useRow" value="11"/>
</appSettings>

<connectionStrings/>
<system.web>

</system.web>
</configuration>

读取的函数

 1 public IList AppConfigGet(string keyName)
2 {
3 string strReturn = string.Empty;
4 XmlDocument document = new XmlDocument();
5 document.Load(Server.MapPath("~/RealManage/RealActComputeDisparch.config"));
6 ArrayList list = new ArrayList();
7 XmlNodeList nodes = document.GetElementsByTagName("add");
8 for (int i = 0; i < nodes.Count; i++)
9 {
10 XmlAttribute attribute = nodes[i].Attributes["key"];
11 if (attribute != null && (attribute.Value == keyName))
12 {
13 attribute = nodes[i].Attributes["value"];
14 if (attribute != null)
15 {
16 list.Add(attribute.Value);
17
18 }
19 }
20 }
21 return list;
22 }

在调用这个函数是要注意

 

IList list = AppConfigGet("useRow");
foreach(string row in list)//此处的string是list里面的值的类型
{。。。}




posted @ 2011-11-23 14:38  魔都_XL  阅读(246)  评论(0编辑  收藏  举报