zoukankan      html  css  js  c++  java
  • ConfigurationManager.OpenExeConfiguration 打开 app.config 之后 save 似乎不起作用?

    update 2009-06-21

    代码所修改的并不是app.config,而是[Application_Name].exe.config这个文件。

    其中Application_Name就是你的可执行文件的文件名,而[Application_Name].exe.config才是真正起作用的配置文件。

    至于app.config,我认为把它理解为是初始化配置文件比较合适。

    -----------------------------------------------------------

    一下这段代码来自MSDN Library,但是我不明白的是,为什么对于app.config的修改,似乎并没有能够反映到app.config文件中?似乎save并没有起作用


    // Show how to use OpenExeConfiguration(ConfigurationUserLevel) 
    // and RefreshSection.
    static void UpdateAppSettings()
    {
        
    // Get the configuration file.
        System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(  ConfigurationUserLevel.None);

        
    // Add an entry to appSettings.
        int appStgCnt = ConfigurationManager.AppSettings.Count;
        
    string newKey = "NewKey" + appStgCnt.ToString();

        
    string newValue = DateTime.Now.ToLongDateString() + " " +           DateTime.Now.ToLongTimeString();

        config.AppSettings.Settings.Add(newKey, newValue);

        
    // Save the configuration file.
        config.Save(ConfigurationSaveMode.Modified);

        
    // Force a reload of the changed section.
        ConfigurationManager.RefreshSection("appSettings");

    }
    Done is better than perfect.
  • 相关阅读:
    Modbus: 1. Java使用Modbus读取Slave端数据(TCP)
    Nodejs后台发送https请求验证证书
    Cocos2d-JS: 2.编译到安卓和iOS
    Cocos2d-JS: 1.环境搭建
    [转载]聪明人为什么不统治世界——从围棋到德州扑克
    [转载] 国内外GIS方面的网站(较全)
    [转载]土豪算法(笑话也是实话)
    [转载]混沌理论三原则
    [转]追MM的各种算法
    [转载]建筑美和数学美
  • 原文地址:https://www.cnblogs.com/zhaorui/p/20080107_OpenExeConfiguration.html
Copyright © 2011-2022 走看看