读取config文件中的键值
生活随笔
收集整理的這篇文章主要介紹了
读取config文件中的键值
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
新建個config文件
<?xml version="1.0" encoding="utf-8"?><!--
注意: 除了手動編輯此文件以外,您還可以使用 Web 管理工具來
配置應用程序的設置。
可以使用 Visual Studio 中的“網(wǎng)站”->“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>
讀取的函數(shù)
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 }
在調(diào)用這個函數(shù)是要注意
?
IList list = AppConfigGet("useRow");foreach(string row in list)//此處的string是list里面的值的類型
{。。。}
轉(zhuǎn)載于:https://www.cnblogs.com/modu-xl/archive/2011/11/23/2260290.html
總結(jié)
以上是生活随笔為你收集整理的读取config文件中的键值的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [转]一个老工程师给年轻工程师的忠告
- 下一篇: 基于Extjs的OPOA