C#对Web.config的读写操作
来源:互联网 发布:tv霸网络电视在线直播 编辑:程序博客网 时间:2024/05/14 18:07
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 HeNWry.Model;
using HeNWry.BLL;
using System.Configuration;
using System.Xml;
public void read()
{
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=="appSettings")
{
XmlNodeList node=element.ChildNodes;
if ( node.Count > 0 )
{
foreach(XmlElement el in node)
{
switch(el.Attributes["key"].Value)
{
case "day":
this.txtDAY.Text = el.Attributes["value"].Value;
break;
case "hour":
this.txtHOUR.Text = el.Attributes["value"].Value;
break;
case "min":
this.txtMiM.Text = el.Attributes["value"].Value;
break;
}
}
}
}
}
}
public void write()
{
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=="appSettings")
{
XmlNodeList node=element.ChildNodes;
if ( node.Count > 0 )
{
foreach(XmlElement el in node)
{
switch(el.Attributes["key"].Value)
{
case "day":
el.Attributes["value"].Value = this.txtDAY.Text;
break;
case "hour":
el.Attributes["value"].Value =this.txtHOUR.Text;
break;
case "min":
el.Attributes["value"].Value =this.txtMiM.Text;
break;
}
}
}
}
}
xmldoc.Save(filename);
}
public void resert()
{
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=="appSettings")
{
XmlNodeList node=element.ChildNodes;
if ( node.Count > 0 )
{
foreach(XmlElement el in node)
{
switch(el.Attributes["key"].Value)
{
case "day":
el.Attributes["value"].Value = "0";
break;
case "hour":
el.Attributes["value"].Value ="6";
break;
case "min":
el.Attributes["value"].Value = "10";
break;
}
}
}
}
}
xmldoc.Save(filename);
}
public static string Gettime()
{
string day="";
string hour="";
string min="";
Page dd = new Page();
string filename= dd.Server.MapPath("/")+@"Web.config";
XmlDocument xmldoc= new XmlDocument();
xmldoc.Load(filename);
XmlNodeList topM=xmldoc.DocumentElement.ChildNodes;
foreach(XmlElement element in topM)
{
if(element.Name=="appSettings")
{
XmlNodeList node=element.ChildNodes;
if ( node.Count > 0 )
{
foreach(XmlElement el in node)
{
switch(el.Attributes["key"].Value)
{
case "day":
day= el.Attributes["value"].Value;
break;
case "hour":
hour = el.Attributes["value"].Value;
break;
case "min":
min = el.Attributes["value"].Value;
break;
}
}
}
}
}
stringnowtime=DateTime.Now.AddDays(int.Parse("-"+day)).AddHours(int.Parse("-"+hour)).AddMinutes(int.Parse("-"+min)).ToString();
return nowtime;
}
//
web.config
<appSettings>
<add key="day" value="0" />
<add key="hour" value="6" />
<add key="min" value="10" />
</appSettings>
- C#对Web.config的读写操作
- 对web.config的操作
- C# 读写 Web.config
- web.config 读写操作
- C# 读写 Web.config 的类
- C#对App.config文件或者web.config文件中节点的操作类
- 对WEB.Config文件进行(读写操作)
- 对WEB.Config文件进行(读写操作)
- c#操作web.config
- 对Web.Config配置文件的常见操作
- 对web.config文件的操作类
- C#中对Web.config配置文件的操作(增删改读)
- C#中对Web.config配置文件的操作(增删改读)
- c#中对web.config配置文件的操作(增删改读)
- C#中对Web.config配置文件的操作(增删改读)
- C#对EXCEL的读写操作
- C#对*.ini文件的读写操作
- C#对EXCEL的读写操作
- [数据库连接字符串] Access 连接字符串(转)
- #ifdef的嵌套使用
- linux--文件時間
- Oracle中关于处理小数点位数的几个函数,取小数位数,Oracle查询函数
- lighttpd 配置全接触(1)——Lighttpd core
- C#对Web.config的读写操作
- 如何设置视频采集的制式
- 序
- Android adb shell 命令
- eclipse调试技巧
- linux ln 命令的使用
- 探索中间件的性能调优和管理监控,欢迎大家一起来探讨?
- Android画图学习总结(二)——Bitmap
- ubuntu 安装unix2dos和dos2unix