zoukankan      html  css  js  c++  java
  • XML操作App.config的类

    public class DoConfig
        {
            public static void Editconfig(string Key,string Value)                      
            {
                XmlDocument xmldoc = new XmlDocument();
                string filePath = Application.ExecutablePath + ".config";
                xmldoc.Load(filePath);

                XmlNodeList topM = xmldoc.DocumentElement.ChildNodes;
                foreach (XmlElement element in topM)
                {
                    if (element.Name.ToLower() == "appsettings")     //找到要改写的字段名 
                    {
                        XmlNodeList _node = element.ChildNodes;
                        if (_node.Count > 0)
                        {
                            foreach (XmlElement el in _node)
                            {
                                //el.Attributes[Key].Value = Value;                                                                 //查找并改写 
                                if (el.Attributes["key"].Value == Key)
                                    el.Attributes["value"].Value = Value;
                            }
                        }
                    }
                }
                xmldoc.Save(filePath);       //保存改写文件 
            }
        }
  • 相关阅读:
    WCF相关
    MiniUI级联
    大家一起来学 NHibernate+NUnit (VS2012+SQL Server2008)
    C# 复杂算法
    sql自定义日期函数,返回范围内日期和星期数表。
    RDLC开发笔记
    解决IE7和IE6不支持javaScript中的indexOf函数的问题
    Sql获取周、月、年的首尾时间。
    Sql Server中实现Mysql中的group_concat函数效果
    RDLC隔行变色的实现
  • 原文地址:https://www.cnblogs.com/lds85930/p/1124737.html
Copyright © 2011-2022 走看看