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         }
  • 相关阅读:
    Mysql 关于 FOUND_ROWS() 和 ROW_COUNT() 函数
    MySQL数据库远程连接
    MySQL数据库远程连接
    Linux 下不得不说的那些快捷键
    Linux 下不得不说的那些快捷键
    linux实时查看更新日志命令
    linux实时查看更新日志命令
    the current differences between MyISAM and InnoDB storage engines
    Difference Between InnoDb and MyISAM(个人觉着是好文章,简单易懂,推荐看)
    MyISAM to InnoDB: Why and How(MYSQL官方译文)
  • 原文地址:https://www.cnblogs.com/EasyLive2006/p/690094.html
Copyright © 2011-2022 走看看