Write appSettings in external file

后端 未结 3 1101
野性不改
野性不改 2020-12-06 02:34

I have a config file app.exe.config and appSettings section has something like this:


    

        
3条回答
  •  感动是毒
    2020-12-06 03:03

    using an external config file is transparent for the application,

    this part is o.k

    
        
    
    

    and also this:

    
    
    
      
      
      
    
    

    change your code to be like this:

    Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
    config.AppSettings.Settings["var1"].Value = "value 11";
    config.Save(ConfigurationSaveMode.Modified);
    ConfigurationManager.RefreshSection("appSettings");
    

    referring an external configuration file is transparent to the application, so you don't have to call it directly. you can use the default appSetting section in the configuration manager.

    Good luck

提交回复
热议问题