国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

ASP.NET中動態修改web.config中的設置項目(CS頁代碼)

2019-11-18 19:52:41
字體:
來源:轉載
供稿:網友

朋友們可以自行測試,我這里都沒有問題了,鱉了一上午的問題總算解決了

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.sessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.xml ;


namespace Webapplication1
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
PRotected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.Button Button1;

public WebForm1()
{
Page.Init += new System.EventHandler(Page_Init);
}

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
//打開某文件(假設WEB。CONFIG在根目錄中)
string filename=Server.MapPath("/") + @"/web.config";
XmlDocument  xmldoc= new XmlDocument();
xmldoc.Load(filename);

XmlNodeList topM=xmldoc.DocumentElement.ChildNodes;
foreach(XmlElement element in topM)
{
if(element.Name.ToLower()=="appsettings")
{
XmlNodeList _node=element.ChildNodes;
if ( _node.Count >0 )
{
DropDownList1.Items.Clear();
foreach(XmlElement el in _node)
{
DropDownList1.Items.Add(el.Attributes["key"].InnerXml);
}
}
}
}
}
}

private void Page_Init(object sender, EventArgs e)
{
InitializeComponent();
}

#region Web Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{   
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
string filename=Server.MapPath("/") + @"/web.config";
XmlDocument  xmldoc= new XmlDocument();
xmldoc.Load(filename);

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.ToLower()==this.DropDownList1.SelectedItem.Value.ToLower())
{
el.Attributes["value"].Value=this.TextBox1.Text;
}
}
}
}
}
xmldoc.Save(filename);
}
}
}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 茌平县| 灌云县| 曲阳县| 武清区| 巴楚县| 勐海县| 鄂托克旗| 宁陕县| 临桂县| 曲麻莱县| 张家口市| 张北县| 兰坪| 新蔡县| 海晏县| 米泉市| 东莞市| 佳木斯市| 山西省| 南陵县| 商都县| 崇礼县| 潼南县| 九台市| 凭祥市| 丰台区| 尤溪县| 平塘县| 泾阳县| 平山县| 海兴县| 桦南县| 射阳县| 灵寿县| 荃湾区| 平阴县| 加查县| 海晏县| 昌平区| 彭水| 南汇区|