C# 处理web.config

2009年1月21日星期三

C# 处理web.config

在web.config文件中设置此节点:
100001


一下代码先读取在写入:

自动生成的id写入web.config文件,在下次添加是将id加1
string path;
path =Server.MapPath("web.config");
FileStream fs = new FileStream(path,FileMode.Open ,FileAccess.Read ,FileShare.ReadWrite);
XmlDocument xmldoc =new XmlDocument();
xmldoc.Load (fs);

string temPath;

temPath="//appSettings/add[@key ='nothingCode']";
XmlNode tempPath =xmldoc.SelectSingleNode(temPath);

int tem=0;

tem=Convert.ToInt32 (tempPath.InnerText) +1;
Path=tem.ToString();

tempPath.InnerText =Path;
fs.Close();
xmldoc.Save(path);

0 评论:

发表评论