zoukankan      html  css  js  c++  java
  • C#操作config文件

    以下是app.config或web.config的定义,定义了一个参数,键为Isinit,值为false

    <?xml version="1.0"?>
    <configuration>
      <appSettings>
        <add key ="IsInit" value="false"/>
      </appSettings>
    </configuration>

    以下是读和写config文件的方法定义:

      写入:

      internal void settingApp_write(string key, string val)
            {
                System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                config.AppSettings.Settings["IsInit"].Value = val;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("appSettings");
            }

    读取:
            internal string settingApp_read(string key)
            {
                var val = ConfigurationManager.AppSettings[key];
                return val;
            }

    使用方法:

    写入测试:

    settingApp_write("IsInit","true");

    取出测试:

    var setting = settingApp_read("Isinit");

    此级别的修改是项目级别的config文件修改,也就是你最终程序Bin目录下的那个config文件的操作。

  • 相关阅读:
    MAC OS 上appium自动化测试环境搭建
    Vba+access+Excel编程
    测试工具--SoapUI
    python打包代码做.exe文件
    EXCEL 表格常用函数小记
    python学习杂记--读取安卓设备sdcard中的文件列表
    appium三种等待方式
    python学习杂记--处理excel表格
    Docker学习笔记二
    DHCP报文格式
  • 原文地址:https://www.cnblogs.com/jacle169/p/2810792.html
Copyright © 2011-2022 走看看