对web.config进行新增修改删除读取操作
2010-11-24 21:39
716 查看
using System;
using System.Configuration;
using System.Reflection;
using System.Web;
using System.Xml;
public enum ConfigFileType
namespace WebApplication1
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 296px; POSITION: absolute; TOP: 120px" runat="server"
Text="删除"></asp:Button>
<asp:Button id="Button2" style="Z-INDEX: 102; LEFT: 232px; POSITION: absolute; TOP: 120px" runat="server"
Text="新增"></asp:Button>
<asp:Label id="Label1" style="Z-INDEX: 103; LEFT: 104px; POSITION: absolute; TOP: 32px" runat="server">key</asp:Label>
<asp:TextBox id="TextBox1" style="Z-INDEX: 104; LEFT: 168px; POSITION: absolute; TOP: 32px" runat="server"></asp:TextBox>
<asp:Label id="Label2" style="Z-INDEX: 105; LEFT: 104px; POSITION: absolute; TOP: 96px" runat="server">value</asp:Label>
<asp:TextBox id="TextBox2" style="Z-INDEX: 106; LEFT: 168px; POSITION: absolute; TOP: 80px" runat="server"></asp:TextBox>
<asp:Button id="Button3" style="Z-INDEX: 107; LEFT: 360px; POSITION: absolute; TOP: 120px" runat="server"
Text="修改"></asp:Button>
</form>
</body>
</HTML>2.2 cs代码
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 Button2;
private void Page_Load(object sender, System.EventArgs e)
{
}
Web Form Designer generated code#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/**//// <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.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Button3.Click += new System.EventHandler(this.Button3_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button2_Click(object sender, System.EventArgs e)
{
//新增
ReadWriteConfig config = new ReadWriteConfig();
config.ConfigType = (int)ConfigFileType.WebConfig;
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;
config.removeElement(this.TextBox1.Text);
}
private void Button3_Click(object sender, System.EventArgs e)
{
//修改
ReadWriteConfig config = new ReadWriteConfig();
config.ConfigType = (int)ConfigFileType.WebConfig;
config.SetValue(this.TextBox1.Text,this.TextBox2.Text);
}
}3.测试代码下载/Files/singlepine/readwritconfig.rar
if ($ != jQuery) {
$ = jQuery.noConflict();
}
using System.Configuration;
using System.Reflection;
using System.Web;
using System.Xml;
public enum ConfigFileType
namespace WebApplication1
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 296px; POSITION: absolute; TOP: 120px" runat="server"
Text="删除"></asp:Button>
<asp:Button id="Button2" style="Z-INDEX: 102; LEFT: 232px; POSITION: absolute; TOP: 120px" runat="server"
Text="新增"></asp:Button>
<asp:Label id="Label1" style="Z-INDEX: 103; LEFT: 104px; POSITION: absolute; TOP: 32px" runat="server">key</asp:Label>
<asp:TextBox id="TextBox1" style="Z-INDEX: 104; LEFT: 168px; POSITION: absolute; TOP: 32px" runat="server"></asp:TextBox>
<asp:Label id="Label2" style="Z-INDEX: 105; LEFT: 104px; POSITION: absolute; TOP: 96px" runat="server">value</asp:Label>
<asp:TextBox id="TextBox2" style="Z-INDEX: 106; LEFT: 168px; POSITION: absolute; TOP: 80px" runat="server"></asp:TextBox>
<asp:Button id="Button3" style="Z-INDEX: 107; LEFT: 360px; POSITION: absolute; TOP: 120px" runat="server"
Text="修改"></asp:Button>
</form>
</body>
</HTML>2.2 cs代码
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 Button2;
private void Page_Load(object sender, System.EventArgs e)
{
}
Web Form Designer generated code#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/**//// <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.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Button3.Click += new System.EventHandler(this.Button3_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button2_Click(object sender, System.EventArgs e)
{
//新增
ReadWriteConfig config = new ReadWriteConfig();
config.ConfigType = (int)ConfigFileType.WebConfig;
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;
config.removeElement(this.TextBox1.Text);
}
private void Button3_Click(object sender, System.EventArgs e)
{
//修改
ReadWriteConfig config = new ReadWriteConfig();
config.ConfigType = (int)ConfigFileType.WebConfig;
config.SetValue(this.TextBox1.Text,this.TextBox2.Text);
}
}3.测试代码下载/Files/singlepine/readwritconfig.rar
if ($ != jQuery) {
$ = jQuery.noConflict();
}
相关文章推荐
- [转]对web.config进行新增修改删除读取操作
- 对web.config进行新增修改删除读取操作
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
- 对web.config进行新增修改删除读取操作
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
- 对web.config进行新增修改删除读取操作
- 对web.config进行新增修改删除读取操作
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
- 对web.config进行新增修改删除读取操作
- 对web.config进行新增修改删除读取操作
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
- 对web.config进行新增修改删除读取操作
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
- 对web.config进行新增修改删除读取操作
- 对config文件中的配置进行新增修改删除读取操作
- 对appSettings节点进行新增、修改、删除、读取操作的类AppSettingsHelper
- .net操作xml文件(新增.修改,删除,读取)
- C#里对xml文件进行修改,新增,删除,插入操作
- Java读取json文件并对json数据进行读取、添加、删除与修改操作
- 怎样在C#里对xml文件进行修改,新增,删除,插入操作?