zoukankan      html  css  js  c++  java
  • 通过本地exe.config进行配置并修改

    //本机config操作
     Configuration configs = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    configs.AppSettings.Settings.Remove("Version_Number");
                    configs.AppSettings.Settings.Add("Version_Number", newNumber);
                    //一定要记得保存,写不带参数的config.Save()也可以
                    configs.Save();
                    //刷新,否则程序读取的还是之前的值(可能已装入内存)
                    System.Configuration.ConfigurationManager.RefreshSection("appSettings");
    //操作其他程序的config
                    string configPath = Application.StartupPath + @"WindowsFormsApp1.exe.config";//获取到主程序的config,进行修改版本
                    ExeConfigurationFileMap map = new ExeConfigurationFileMap();
                    map.ExeConfigFilename = configPath;
                    Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
                    config.AppSettings.Settings.Remove("Version_Number");
                    config.AppSettings.Settings.Add("Version_Number", newNumber);
                    //一定要记得保存,写不带参数的config.Save()也可以
                    config.Save();
                    //刷新,否则程序读取的还是之前的值(可能已装入内存)
                    System.Configuration.ConfigurationManager.RefreshSection("appSettings");
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <appSettings>
        <add key="Version_Number" value="1"/>
      </appSettings>
    </configuration>
    View Code

  • 相关阅读:
    bzoj2763 [JLOI]飞行路线 分层图最短路
    [模板]分块/可修改莫队 (数颜色种类)
    gcd步数
    洛谷2378 因式分解 字符串
    bzoj1090 字符串折叠
    洛谷1034 NOIP2002 矩形覆盖
    Codeforces#441 Div.2 四*题
    SPFA的小优化
    洛谷1073 NOIP2009 最优贸易
    bzoj2100 [Usaco2010 DEC]Apple Delivery苹果贸易
  • 原文地址:https://www.cnblogs.com/xuezhu/p/12696538.html
Copyright © 2011-2022 走看看