读取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里面的值的类型
{。。。}




转载于:https://www.cnblogs.com/modu-xl/archive/2011/11/23/2260290.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值