Write values in app.config file

后端 未结 10 926
生来不讨喜
生来不讨喜 2020-11-29 01:46

can anyone please help me how can I set/store values in the app.config file using c#, is it possible at all?

10条回答
  •  抹茶落季
    2020-11-29 02:08

    For a .NET 4.0 console application, none of these worked for me. So I used the following below and it worked:

    private static void UpdateSetting(string key, string value)
    {
        Configuration configuration = ConfigurationManager.
            OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
        configuration.AppSettings.Settings[key].Value = value;
        configuration.Save();
    
        ConfigurationManager.RefreshSection("appSettings");
    }
    

提交回复
热议问题