zoukankan      html  css  js  c++  java
  • Web.config的写入操作

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

     1         /// <summary>
     2         /// 修改指定配置节节点信息的值
     3         /// 作    者: KidYang
     4         /// 日    期: 2007-03-27
     5         /// </summary>
     6         /// <param name="appSettingsName">给定配置节节点</param>
     7         /// <param name="newValue">目标值</param>
     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         }
  • 相关阅读:
    SQL Server事务、视图和索引
    软件系统的分层开发
    OOP应用:实体类
    Oracle/MySql/SQL Sqlserver分页查询
    数据库连接语句
    SQL连接查询
    MySQL基本手册
    C# 其他
    numpy的loadtxt()用法
    Pytorch从一个输入目录中加载所有的PNG图像,并将它们存储在张量中
  • 原文地址:https://www.cnblogs.com/EasyLive2006/p/690094.html
Copyright © 2011-2022 走看看