是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的数据如何作呢?我急用,请高人,能人照顾一下。好了立即,奉上。
<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的数据如何作呢?我急用,请高人,能人照顾一下。好了立即,奉上。
解决方案 »
- 帮我解决下这个坐标问题,谢谢
- 一个WEB项目,页面到处都是session["aaa"] 这样的东西,这aaa只要一改名就全乱了,大家是怎么控制这个东西的?
- 存储过程报错
- 在ASP网页中设置控件的HTML属性的问题,读不懂
- 这个效果怎么实现?将搜索结果中的关键字用红色字体显示?
- 求一个类似CSDN的树型菜单,要源码(看代码理解的快些)...
- 关于chartspace控件
- 请测试一个用asp.net+c#做的一个网站
- 安装了msde2000 请问如何设置,如何建立一个数据库!
- 怎样设定被选中节点的样式!!(TreeView)
- 大家好请教一个ViewState的问题。
- 我在想,asp.net 用的是服务器控件,每次都要传到服务器执行再下载到客户端,而asp直接放到IE中解释执行,这样看来似乎asp.net慢啊
真是急用,请帮一下吧。
<appSettings>
<add key="Email" value="Email"/>
<add key="TextType" value="A++"/>
<add key="Info" value="Important"/>
<add key="message" value="非常重要的"/>
</appSettings>
这样就可以轻松的读取了。
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"];
}
}
你说的是,1.1中用的方法,在2.0中已经不支持了,
在2.0中,只支持System.Configuration.ConfigurationManager.GetSection("***");
{
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;
}
}
您写的,好像不是我说的啊。但是还是谢谢。
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>
<configuration>
<myCustomGroup>
<myCustomSection myAttrib1="Clowns">
<myChildSection
myChildAttrib1="Zippy"
myChildAttrib2="Michael Zawondy "/>
</myCustomSection>
</myCustomGroup></configuration>
下面这个对你有帮助哈,你详细看一下.
我是获取远程服务动态返回的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 = " " + mresultdescription;
}
else
{
hidSendMessage.Value += "<br>" + " " + mresultdescription;
} }
}
}
因为,我要作的是所有的配置都映射成相应的静态成员变量,并且是写成只读属性,这样程序通过类似AppConfig.ConnectionString就可以访问。zhangxiaopin(zxp)的,我没有完全看懂,但是也谢谢了。结贴。