写写程序,一种成就的感觉

写写程序,一种成就的感觉

导航

asp.net操作XML

Posted on 2010-06-21 14:05  hateyoucode  阅读(220)  评论(0编辑  收藏  举报
代码
using System;
using System.Xml;

public partial class Web_Admin_Admin_Basic : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string sFile = Server.MapPath("../Web.config");
XmlDocument xmldoc
= new XmlDocument();
xmldoc.Load(sFile);

XmlNodeList topm
= xmldoc.DocumentElement.ChildNodes;
foreach (XmlElement element in topm)
{
if (element.Name.ToLower() == "appsettings")
{
XmlNodeList _node
= element.ChildNodes;
if (_node.Count > 0)
{
foreach (XmlElement el in _node)
{
if (el.Attributes["key"].InnerXml == "IsOpenWin")
RadioButtonList1.SelectedValue
= el.Attributes["value"].Value;
}
}
}
}
}
}

protected void Button1_Click(object sender, EventArgs e)
{
string sFile = Server.MapPath("../Web.config");
XmlDocument xmldoc
= new XmlDocument();
xmldoc.Load(sFile);

XmlNodeList topm
= xmldoc.DocumentElement.ChildNodes;
foreach (XmlElement element in topm)
{
if (element.Name.ToLower() == "appsettings")
{
XmlNodeList _node
= element.ChildNodes;
if (_node.Count > 0)
{
foreach (XmlElement el in _node)
{
if (el.Attributes["key"].InnerXml == "IsOpenWin")
el.Attributes[
"value"].Value = RadioButtonList1.SelectedValue;
}
}
}
}
xmldoc.Save(sFile);
Common.Message(
"<script>alert('修改成功');location.href='Admin_Basic.aspx'</script>");
}
}