zoukankan      html  css  js  c++  java
  • WinForm OR ASP.NET获取修改配置文件config的节点

    获取appSettings节点下 键值对

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <add key="versions" value="1.0.0.0"/>
        <add key="terminal" value="1"/>
      </appSettings>
    </configuration>

    代码如下:

    System.Configuration.AppSettingsReader appSettings = new System.Configuration.AppSettingsReader();
    appSettings.GetValue("versions", Type.GetType("System.String")).ToString();

    获取Connectionstings节点 

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>
        </configSections>
        <connectionStrings>
            <add name="ConnStr"  connectionString="server=.;database=dbTest;uid=sa;pwd=123456;"/>
        </connectionStrings>
    </configuration>

    代码如下:

    using System.Configuration; 
    string con=ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString; 

    修改appSettings节点

    /// <summary>
            
    /// 修改键值
            
    /// </summary>
            
    /// <param name="key"></param>
            
    /// <param name="value"></param>
            public static void saveAppSetting(string key, string value)
            {
                System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                config.AppSettings.Settings[key].Value = value;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("appSettings");
            }
  • 相关阅读:
    CORS详解
    Function program language
    Hello2实例的分析
    Tomcat服务器安装及配置
    案例ORA-00600: internal error code, arguments: [qkaffsindex3], [], [], [], []
    SQL Server新老版本CE区别
    SQL Server标量函数改写内联表值函数优化案例
    SQL Server 2016升级迁移过程中性能问题诊断案例
    Oracle dba角色和sysdba的区别
    SQL Server阻塞blocking案例分析
  • 原文地址:https://www.cnblogs.com/junjie94wan/p/2756811.html
Copyright © 2011-2022 走看看