动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   .Net → 阅读文章

 ASP.NET中动态修改web.config中的设置项目(CS页代码)

作者来源: 
阅读 1984 人次 , 2006-3-29 4:33:00 


朋友们可以自行测试,我这里都没有问题了,鳖了一上午的问题总算解决了

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

 本文TagsC#  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:ASP.NET中动态修改web.config中的设置项目(前台代码)
· 下一篇:饼图的一种画法
· asp+ 制作图形
· asp.net高级教程(五)---实战篇(中)    
· 在ASP.NET中使用.NET组件
· asp+ 现在已经被官方正式更名为 asp.net
· ASP.NET ViewState 初探


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077