0

I have an App.config with this code

<appSettings>
  <add key="dataPath" value="" />
  <add key="databaseConnectionString" value="MultipleActiveResultSets=True;SERVER=;DATABASE=;UID=;PWD=" />
  <add key="APIaddress" value="" />
  <add key="Timer" value="1" />
  <add key="BufferSize" value="100" />
  <add key="fisrtConfig" value="1" />
  <add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>

I can access to these values with this code

Srv = System.Configuration.ConfigurationManager.AppSettings("APIaddress").ToString()
timer = CInt(System.Configuration.ConfigurationManager.AppSettings("TimerEsecuzione").ToString())
connectionString = System.Configuration.ConfigurationManager.AppSettings("databaseConnectionString").ToString()
BufferSize = System.Configuration.ConfigurationManager.AppSettings("BufferSize").ToString()
isFirstConfig = IIf(System.Configuration.ConfigurationManager.AppSettings("fisrtConfig").ToString() = 1, True, False)

During my code run, I would to update one of these. I tried differents type of code but no one can update it. These are code I tried:

  • First

    Dim configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
    Dim settings = configFile.AppSettings.Settings
    settings("fisrtConfig").Value = 0
    configFile.Save(ConfigurationSaveMode.Modified)
    ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name)
    
  • Second

    ConfigurationManager.AppSettings.Item("fisrtConfig") = 0
    

Can you help me please?

Swim89
  • 290
  • 8
  • 28
  • 2
    Refer: https://stackoverflow.com/questions/453161/best-practice-to-save-application-settings-in-a-windows-forms-application – NoviceProgrammer Feb 21 '18 at 09:35
  • [This example](http://www.vbforums.com/showthread.php?532768-NET-2-0-Protected-Configuration-(Encrypting-Config-Files)&highlight=) may be useful. – jmcilhinney Feb 21 '18 at 09:48

0 Answers0