是Web.Config中的<?xml version="1.0" encoding="utf-8"?><configuration>
  <configSections>
    <sectionGroup name="F1">
      <section name="F2" type="Student.Test,Student"/>
    </sectionGroup>
  </configSections>
  <F1>
    <F2>
      <F3 name="Email" TextType="A++" Info="Important" message="{0} 非常重要的"/>
      <F3 name="Email1" TextType="A" Info="level1" message="{0}一般!"/>
    <F3 name="Email2" TextType="A+" Info="level2" message="{0}平常{1}!"/>
          </F2>
  </F1>
    <appSettings/>
    <connectionStrings/>
  
    <system.web>
     
        <compilation debug="true" />
              <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
    </system.web>
</configuration>
我想取得自定义配置节F2组中,F3 的Email2 的TextType,Info,message的数据如何作呢?我急用,请高人,能人照顾一下。好了立即,奉上。

解决方案 »

  1.   

    thanks to ls
    真是急用,请帮一下吧。
      

  2.   

    建议你定义成如下格式:
                 <appSettings>
    <add key="Email" value="Email"/>
    <add key="TextType" value="A++"/>
                      <add key="Info" value="Important"/>
                      <add key="message" value="非常重要的"/>
        </appSettings>
    这样就可以轻松的读取了。
      

  3.   

    @Cherish20(Delphi & C#,ASP.NET)谢谢了,但是经理不让改,必须是这个格式(可能涉及到别的模块)。急,
      

  4.   

    可以创建自定义配置节,让应用程序在运行时读取。将配置节信息分组,置于配置文件的两个主要区域:配置节声明区域和配置节设置区域。将配置节声明置于   <configSections>   元素中。在   <configSections>   元素内的   <section>   元素中声明新配置节,即可创建新配置节。<section>   元素有两个属性:     
      name   属性,它是元素的名称,该元素包含节处理程序读取的信息。     
      type   属性,它是类的名称,该类读取信息。     
      配置设置的语法取决于与配置节关联的节处理程序。有关更多信息,请参见配置节架构。   
      下面的示例说明如何声明自定义节,该节使用   SingleTagSectionHandler   类。   
      <configuration>   
              <configSections>   
                      <section   name="sampleSection"   
                                        type="System.Configuration.SingleTagSectionHandler"   />   
              </configSections>   
        
              <sampleSection   setting1="Value1"   setting2="value   two"     
                                            setting3="third   value"   />   
      </configuration>   
      访问自定义配置节   
      可以使用静态方法   System.Configuration.ConfigurationSettings.GetConfig   来从应用程序访问配置设置。实现   System.Configuration.IConfigurationSectionHandler   的类计算   GetConfig   方法返回的设置。由于   IConfigurationSectionHandler.Create   方法的返回值是   Object   类型,所以必须将对象强制转换为节处理程序创建的类型。   
      若要从   sampleSection   读取设置,请将   ConfigurationSettings.GetConfig   返回的对象强制转换为   IDictionary   对象。   
      下面的代码说明如何从配置文件中检索设置。   
        
      [C#]   
      using   System;   
      using   System.Collections;   
      using   System.Configuration;   
        
      class   MyConfigurationReader   {   
          
              public   void   ReadMySettings()   {   
                      IDictionary   sampleTable   =   (IDictionary)     
                              ConfigurationSettings.GetConfig("sampleSection");   
                      string   value1   =   (string)sampleTable["setting1"];   
                      string   value2   =   (string)sampleTable["setting2"];   
                      string   value3   =   (string)sampleTable["setting3"];   
              }   
      }   
      

  5.   

    http://blog.csdn.net/yes555/archive/2006/05/06/710451.aspx
      

  6.   

    bigmingming(明明兄)
    你说的是,1.1中用的方法,在2.0中已经不支持了,
    在2.0中,只支持System.Configuration.ConfigurationManager.GetSection("***");
      

  7.   

    public static bool appSettingsEdit(string WebConfigDirectory, string appSettingsAddkey, string keyvalue)
        {
            try
            {
                string path = WebConfigDirectory + "system.config";
                XmlDocument xd = new XmlDocument();
                xd.Load(path);            //****如果没有appSetting,则添加  
                //****//appSettings表示你要获取xml节点如果没有的话创建引结点
                if (xd.SelectNodes("//appSettings").Count == 0)
                {
                    xd.DocumentElement.AppendChild(xd.CreateElement("appSettings"));
                }            //****判断节点是否存在,如果存在则修改当前节点  
                //*****"/configuration/appSettings/add表示需要获取点的的值
                bool addNode = true;
                foreach (XmlNode xn1 in xd.SelectNodes("/configuration/appSettings/add"))
                {
                    if (xn1.Attributes["key"].Value == appSettingsAddkey)
                    {
                        addNode = false;
                        xn1.Attributes["value"].Value = keyvalue;
                        //xn1.ParentNode.RemoveChild(xn1);  
                        break;
                    }
                }            //****当前节点不存在,则添加新节点  
                if (addNode)
                {
                    //****创建新节点  
                    XmlNode xn2 = xd.CreateElement("add");                //****添加key  
                    XmlAttribute xa = xd.CreateAttribute("key");
                    xa.Value = appSettingsAddkey;
                    xn2.Attributes.Append(xa);                //****添加value  
                    xa = xd.CreateAttribute("value");
                    xa.Value = keyvalue;
                    xn2.Attributes.Append(xa);
                    xd.SelectSingleNode("/configuration/appSettings").AppendChild(xn2);
                }            //****保存web.config  
                xd.Save(path);
                return true;
            }
            catch
            {
                return false;
            }
        }
      

  8.   

    @zhangxiaopin(zxp)
    您写的,好像不是我说的啊。但是还是谢谢。
      

  9.   

    <%@ Page Language="C#" %><script runat="server">
        protected void Button1_Click(object sender, EventArgs e)
          {
              MyConfigSectionHandler.MyHandler config =
                  (MyConfigSectionHandler.MyHandler)System.Configuration.ConfigurationManager.GetSection(
                  "myCustomGroup/myCustomSection");
              
              StringBuilder sb = new StringBuilder();          sb.Append("<h2>Attributes in the myCustomSection Element:</h2>");
              sb.AppendFormat("myAttrib1 = {0}<br/>", config.MyAttrib1.ToString());
              sb.Append("<h2>Attributes in the myChildSection Element:</h2>");
              sb.AppendFormat("myChildAttrib1 = {0}<br/>", config.MyChildSection.MyChildAttribute1.ToString());
              sb.AppendFormat("myChildAttrib2 = {0}<br/>", config.MyChildSection.MyChildAttribute2.ToString());          Label1.Text = sb.ToString();
              Label1.Visible = true;
          }
    </script><html    >
    <head runat="server">
          <title>Untitled Page</title>
    </head>
    <body>
          <form id="form1" runat="server">
          <div>
          
          <h1>Enumerate MyCustomSection</h1>
          <asp:Label ID="Label1" runat="server" 
              Text="" />
          <br />
          <asp:Button ID="Button1" runat="server" 
              Text="Get Custom Config Info" 
              OnClick="Button1_Click" />      </div>
          </form>
    </body>
    </html>
      

  10.   

    在 Web.config 文件的配置节设置区域中添加自定义配置元素。
    <configuration>
        <myCustomGroup>
          <myCustomSection myAttrib1="Clowns">
            <myChildSection 
                myChildAttrib1="Zippy" 
                myChildAttrib2="Michael Zawondy "/>
          </myCustomSection>
        </myCustomGroup></configuration>
      

  11.   


    下面这个对你有帮助哈,你详细看一下.
    我是获取远程服务动态返回的xml文件的内容,你说得那种方法也一样得哈.foreach (string F_PZZB_ID in DBParamters)
            {
                if (F_PZZB_ID != "")
                {
                    //*****生成要发送的凭证NC XML接口
                    string BulidPZNCXmlFile = Build_PZ_XML(Convert.ToInt64(F_PZZB_ID), false);                string NCReturnString = "";
                    //****得到NC返回来的接口
                    NCReturnString = HTTPPostPZ(BulidPZNCXmlFile, false);                if (NCReturnString != "")
                    {
                        //****加载返回业的XML文件
                        XmlDocument XmlDoc = new XmlDocument();                    //****加载NC 返回的XML文件
                        XmlDoc.LoadXml(NCReturnString);                    System.Xml.XmlElement root = XmlDoc.DocumentElement;
                        XmlNode xmlNode = root.SelectSingleNode("//resultcode");                    //****获取传递凭证,返回文档信息
                        XmlNode resultdescription = root.SelectSingleNode("//resultdescription");       
                        //****得到返回来的状态哈
                        int resultcode = Convert.ToInt32(xmlNode.InnerText);                    //****获取返回来的文件说明信息
                        string mresultdescription = resultdescription.InnerText.Replace("\r\n", "").Replace("\r", "").Replace("\n", "");
                        switch (resultcode)
                        {
                            case 1://*****发送成功
                                string txtPZBH = XmlDoc.GetElementsByTagName("content")[0].Value;
                                double F_VOUCHER_ID = Convert.ToInt64(txtPZBH == "" ? "0" : txtPZBH);
                                //****更新传递状态
                                AppLibrary.AppGlobal.UpdatePZSendState(Convert.ToInt64(F_PZZB_ID), F_VOUCHER_ID);                            //****记录传凭成功条数
                                Securiyt++;
                                break;
                            case -1://*****发送重复
                                //****记录传递重复条数
                                Repeat++;
                                break;
                            default://*****没有发送成功哈
                                //*****记录传递失败条数
                                Error++;
                                break;                    }                    if (hidSendMessage.Value == "")
                        {
                            hidSendMessage.Value = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + mresultdescription;
                        }
                        else
                        {
                            hidSendMessage.Value += "<br>" + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + mresultdescription;
                        }                }
                }
            }
      

  12.   

    谢谢各位了,但是我觉得  octverve(无人无我观自在,非空非色见如来--炎之脉) ( ) 信誉:100 的好一些。
    因为,我要作的是所有的配置都映射成相应的静态成员变量,并且是写成只读属性,这样程序通过类似AppConfig.ConnectionString就可以访问。zhangxiaopin(zxp)的,我没有完全看懂,但是也谢谢了。结贴。