Chinaunix首页 | 论坛 | 博客
  • 博客访问: 504784
  • 博文数量: 106
  • 博客积分: 5000
  • 博客等级: 大校
  • 技术积分: 1380
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-21 09:35
文章分类

全部博文(106)

文章存档

2010年(3)

2009年(14)

2008年(55)

2007年(34)

我的朋友

分类: 系统运维

2008-09-22 16:05:12

读的过程很容易,下面给出写入

 1         /// 
 2         /// 修改指定配置节节点信息的值
 3         /// 作    者: KidYang
 4         /// 日    期: 2007-03-27
 5         /// 

 6         /// 给定配置节节点
 7         /// 目标值
 8         public static void WriteWebConfig(string appSettingsName, string newValue)
 9         {
10             string fileName = HttpContext.Current.Server.MapPath(@"~\Web.config");
11             XmlDocument xmlDoc = new XmlDocument();
12             xmlDoc.Load(fileName);
13             XmlNodeList topM = xmlDoc.DocumentElement.ChildNodes;
14             foreach (XmlElement element in topM)
15             {
16                 #region 取得目标节点,并赋新值
17 
18                 if (element.Name == "appSettings")
19                 {
20                     XmlNodeList node = element.ChildNodes;
21                     if (node.Count > 0)
22                     {
23                         foreach (XmlElement el in node)
24                         {
25                             if (el.Attributes["key"].Value == appSettingsName)
26                             {
27                                 el.Attributes["value"].Value = newValue;
28                                 xmlDoc.Save(fileName);
29                                 return;
30                             }
31                         }
32                     }
33                 }
34 
35                 #endregion
36             }
37         }
阅读(859) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~