Read the key value in the config file

Source: Internet
Author: User

Create a config File

<? Xml version = "1.0" encoding = "UTF-8"?>
<! --
Note: In addition to manually editing this file, you can also use the Web management tool
Configure application settings.
You can use the "website"> "Asp. Net configuration" option in Visual Studio.
The complete list of settings and comments is displayed in machine. config. comments,
This file is usually located in
\ Windows \ Microsoft. Net \ Framework \ v2.x \ Config
-->
<Configuration>
<Deleetask>
<! -- The row to be sent -->
<Add key = "useRow" value = "7"/>
<! -- The row to be sent -->
<Add key = "useRow" value = "8"/>
<! -- The row to be sent -->
<Add key = "useRow" value = "9"/>
<! -- The row to be sent -->
<Add key = "useRow" value = "10"/>
<! -- The row to be sent -->
<Add key = "useRow" value = "11"/>
</AppSettings>

<ConnectionStrings/>
<System. web>

</System. web>
</Configuration>

Read Functions

 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 }

When calling this function, note that

 

IList list = AppConfigGet ("useRow ");
Foreach (string row in list) // here the string is the type of the value in list
{...}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.