zoukankan      html  css  js  c++  java
  • c#配置文件appStrings配置节的读取、添加和修改

    程序开发中经常会用到应用程序配置文件,好处就是维护人员可以直接修改配置文件进行维护,而不用修改程序。好,切入主题。

    给项目添加应用程序配置文件App.config,先在里面写几句:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <add key="1" value="内容一"/>
        <add key="2" value="内容二"/>
        <add key="3" value="内容三"/>
      </appSettings>
    </configuration>

      读取内容:老写法是System.Configuration.ConfigurationSettings.AppSettings[“1”].ToString();  这个"1"对应里面的key。
    这里推荐在引用里添加System.configuration,命名空间加入using System.Configuration;

    就可以写成  ConfigurationManager.AppSettings["key"].ToString(); 这里的key就是1、2、3啦。

      添加内容:

     

                Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                cfa.AppSettings.Settings.Add("key", "value");
                //最后调用save
                cfa.Save();
                // 刷新命名节,在下次检索它时将从磁盘重新读取它。记住应用程序要刷新节点
                ConfigurationManager.RefreshSection("appSettings");
                MessageBox.Show("添加成功");

      修改内容:

                Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                cfa.AppSettings.Settings["key名称"].Value = "要改成的value值";
                cfa.Save();
                ConfigurationManager.RefreshSection("appSettings");

      删除内容:

                cfa.AppSettings.Settings.Remove("要删除的key名");
                cfa.Save();

      简单的几个操作就是这些,往大牛们多指教^_^

  • 相关阅读:
    HCL AppScan Standard 9.0.3.13
    appscan 9.0.3.12 版本下载--补丁验证---win10 验证OK
    appscan 9.0.3.10 版本及补丁下载
    appscan 历史版本下载
    Python 批量文件下载
    广告URL
    Linux 修改hostname几种方式
    Kali系统 metasploit 使用教程
    Metasploit
    NIKTO
  • 原文地址:https://www.cnblogs.com/wuyouyu/p/3364675.html
Copyright © 2011-2022 走看看