c#中对web.config配置文件的操作(增删改读)

// c#中对web.config配置文件的操作(增删改读)

using  system;
using  system.configuration;
using  system.reflection;
using  system.web;
using  system.xml;
public   enum  configfiletype
{
 webconfig,
 appconfig
}


namespace  configrw
{
 
/// <summary>
 
/// summary description for readwriteconfig.
 
/// </summary>

 public class readwriteconfig
 
{  
  
public string docname = string.empty; 
  
private xmlnode node=null;    
  
private int _configtype; 
  
public string message;
  
public int configtype
  
{
   
getreturn _configtype; }
   
set{ _configtype=value; }
  }
  

  
getvalue

  
setvalue

  
saveconfigdoc

  
removeelement

  
modifyelement

  
loadconfigdoc
 }

}


 

测试页面

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;

namespace  configrw
{
 
/// <summary>
 
/// summary description for webform1.
 
/// </summary>

 public class webform1 : system.web.ui.page
 
{
  
protected system.web.ui.webcontrols.button button1;
  
protected system.web.ui.webcontrols.label label1;
  
protected system.web.ui.webcontrols.textbox textbox1;
  
protected system.web.ui.webcontrols.label label2;
  
protected system.web.ui.webcontrols.textbox textbox2;
  
protected system.web.ui.webcontrols.button button3;
  
protected system.web.ui.webcontrols.button button4;
  
protected system.web.ui.webcontrols.button button2;
 
  
private void page_load(object sender, system.eventargs e)
  
{
   
  }


  
web form designer generated code

  
private void button2_click(object sender, system.eventargs e)
  
{
   
//新增
   readwriteconfig config = new readwriteconfig();   
   config.configtype 
= (int)configfiletype.webconfig; 
   response.write(config.setvalue(
this.textbox1.text,this.textbox2.text));
  }


  
private void button1_click(object sender, system.eventargs e)
  
{
   
//删除
   readwriteconfig config = new readwriteconfig();   
   config.configtype 
= (int)configfiletype.webconfig; 
   response.write(config.removeelement(
this.textbox1.text));
  }


  
private void button3_click(object sender, system.eventargs e)
  
{
   
//修改
   readwriteconfig config = new readwriteconfig();   
   config.configtype 
= (int)configfiletype.webconfig; 
   response.write(config.modifyelement(
this.textbox1.text,this.textbox2.text));
  }


  
private void button4_click(object sender, system.eventargs e)
  
{
   
//读取
   readwriteconfig config = new readwriteconfig();   
   config.configtype 
= (int)configfiletype.webconfig; 
   
this.textbox2.text = config.getvalue(this.textbox1.text);
  }

 }

}


 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值