zoukankan      html  css  js  c++  java
  • 动态修改配置文件节点

    View Code
     ///<summary>
    /// 更新某个节点中的值
    ///</summary>
    private void updata()
    {
    XmlDocument xmlDoc = new XmlDocument();

    xmlDoc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);

    foreach (XmlElement element in xmlDoc.DocumentElement)
    {
    if (element.Name.Equals("appSettings"))
    {
    foreach (XmlNode node in element.ChildNodes)
    {
    if (node.Attributes[0].Value.Equals("t5"))
    {
    node.Attributes[1].Value = "aaaa";
    }
    }
    }
    }
    xmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);

    ConfigurationManager.RefreshSection("appSettings"); //强制加载新的 配置文件
    }
    View Code
     1  ///<summary>
    2 /// 查看
    3 ///</summary>
    4 private void showconfig()
    5 {
    6 foreach (string key in ConfigurationManager.AppSettings) //遍历得到所有 appsetting 节点
    7 {
    8 string value = ConfigurationManager.AppSettings[key];
    9 Response.Write(string.Format("key:{0},value:{1}", key, value)+"<br>");
    10 }
    11
    12 }




    作者:javaoraspx
    出处:http://www.cnblogs.com/xyong/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    0.1.3 set的用法
    JoinPoint
    砝码组合(dfs)
    强大的【环绕通知】
    applicationContext.xml 模板
    各种jar包
    装饰博客(二)添加宠物
    装饰博客(一)添加背景图片
    拖拽功能的实现
    点击之后连接qq
  • 原文地址:https://www.cnblogs.com/xyong/p/2260471.html
Copyright © 2011-2022 走看看