Hi all,
I know its not the best way around doing this but i do have a viable need to change a value in a windows applications app.config file. I also need it to refresh the config settings at runtine avoiding the need to restart the application for the changes to take effect.
I have 2 options to change the config file but the 2nd seens to fail on the update setting section.
Option 1 edit using the xmlDocument method.
Public Shared Sub Set_DefaultApplicationServer_ForClient()
Dim strPathToCfg As String = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
Dim xmlDoc As New XmlDocument
xmlDoc.Load(strPathToCfg)
Dim xmlNavigator As XPathNavigator = xmlDoc.CreateNavigator
xmlNavigator.SelectSingleNode("//setting[@name='FILA_ClientApplication_FILA_AppSvrMain_FILA_ApplicationServer']/value").SetValue("
xmlDoc.Save(strPathToCfg)
End Sub
This works once the application restarts.
Option 2 using the Configuration Manager.
Public Shared Sub UpdateAppSettings()
Dim config As System.Configuration.Configuration = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
' Update the setting. - FAILS HERE
config.AppSettings.Settings("//setting[@name='FILA_ClientApplication_FILA_AppSvrMain_FILA_ApplicationServer']/value").Value = "
' Save the configuration file.
config.Save(ConfigurationSaveMode.Modified)
' Force a reload of the changed section.
ConfigurationManager.RefreshSection("appSettings")
End Sub
Whether i have the values incorrect i have no idea.
Many thanks
I know its not the best way around doing this but i do have a viable need to change a value in a windows applications app.config file. I also need it to refresh the config settings at runtine avoiding the need to restart the application for the changes to take effect.
I have 2 options to change the config file but the 2nd seens to fail on the update setting section.
Option 1 edit using the xmlDocument method.
Public Shared Sub Set_DefaultApplicationServer_ForClient()
Dim strPathToCfg As String = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
Dim xmlDoc As New XmlDocument
xmlDoc.Load(strPathToCfg)
Dim xmlNavigator As XPathNavigator = xmlDoc.CreateNavigator
xmlNavigator.SelectSingleNode("//setting[@name='FILA_ClientApplication_FILA_AppSvrMain_FILA_ApplicationServer']/value").SetValue("
xmlDoc.Save(strPathToCfg)
End Sub
This works once the application restarts.
Option 2 using the Configuration Manager.
Public Shared Sub UpdateAppSettings()
Dim config As System.Configuration.Configuration = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
' Update the setting. - FAILS HERE
config.AppSettings.Settings("//setting[@name='FILA_ClientApplication_FILA_AppSvrMain_FILA_ApplicationServer']/value").Value = "
' Save the configuration file.
config.Save(ConfigurationSaveMode.Modified)
' Force a reload of the changed section.
ConfigurationManager.RefreshSection("appSettings")
End Sub
Whether i have the values incorrect i have no idea.
Many thanks