Save and reload app.config(applicationSettings) at runtime

前端 未结 4 478
攒了一身酷
攒了一身酷 2020-12-01 16:57

I\'ve stored configuration of my application in the app.config, by Visual Studio I\'ve created some application key on the settings tab of project properties dialog, then I\

相关标签:
4条回答
  • 2020-12-01 17:05

    I did a some tests and here is result.

    For auto generated class Settings the call of ConfigurationManager.RefreshSection("applicationSettings"); doesn't apply the modified values for members marked with ApplicationScopedSettingAttribute, it applies the changes to future calls via ConfigurationManager members (and not sure about UserScopedSettingAttribute).

    Instead call Settings.Default.Reload();

    0 讨论(0)
  • 2020-12-01 17:11

    You need to make a call to ConfigurationManager.RefreshSection in order to have the values re-read from disk.

    0 讨论(0)
  • 2020-12-01 17:24

    Aleroot's code for updating values worked fine. In spite of Properties.Settings being write only (no set).

    To refresh, this worked for me: ConfigurationManager.RefreshSection("applicationSettings");

    But I'm using this to access the parameter: string test = Properties.Settings.Default.MyString; MessageBox.Show("Paramètres/Settings MyString = " + test);

    0 讨论(0)
  • 2020-12-01 17:25

    What you want is accomplish able by creating an custom ConfigSection which allows you more control and allows you to change the name. Configuration manager has a refresh section which will allow you reload the data.

    0 讨论(0)
提交回复
热议问题