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

首頁 > 編程 > ASP > 正文

ASP。NET程序中動態修改web.config中的設置項目 (后臺CS代碼)

2024-05-04 11:06:32
字體:
來源:轉載
供稿:網友
朋友們可以自行測試,我這里都沒有問題了,鱉了一上午的問題總算解決了

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);
}
}
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 通州区| 万载县| 凤城市| 洛扎县| 兰西县| 新龙县| 德令哈市| 桂平市| 双峰县| 墨江| 城步| 韩城市| 林州市| 芮城县| 郯城县| 金川县| 延津县| 广昌县| 茌平县| 遂平县| 江津市| 商水县| 嵊泗县| 洛宁县| 东乌珠穆沁旗| 深泽县| 内江市| 江西省| 吴堡县| 逊克县| 册亨县| 吉隆县| 昭通市| 台湾省| 石景山区| 太和县| 信阳市| 黄骅市| 北碚区| 环江| 濮阳市|