Write appSettings in external file

后端 未结 3 1094
野性不改
野性不改 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:00

    Finally, I have found a solution.

    The solution is to declare the config file as this:

    
    
      
      
    
    

    And from code

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

    Note that I use GetSection("appSettings") instead of config.AppSettings.Settings

    Thanks to all that help people in StackOverflow.

提交回复
热议问题