{100分},急,加急的,求如何获取“自定义设置节”的值,在线,好了给分。加急的。
是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的数据如何作呢?我急用,请高人,能人照顾一下。好了立即,奉上。
[解决办法]
建议你定义成如下格式:
<appSettings>
<add key= "Email " value= "Email "/>
<add key= "TextType " value= "A++ "/>
<add key= "Info " value= "Important "/>
<add key= "message " value= "非常重要的 "/>
</appSettings>
这样就可以轻松的读取了。
[解决办法]
http://blog.csdn.net/yes555/archive/2006/05/06/710451.aspx
[解决办法]
bigmingming(明明兄)
你说的是,1.1中用的方法,在2.0中已经不支持了,
在2.0中,只支持
System.Configuration.ConfigurationManager.GetSection( "*** ");
[解决办法]
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;
}
}
[解决办法]
<%@ 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>
[解决办法]
在 Web.config 文件的配置节设置区域中添加自定义配置元素。
<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;
}
}
}
}