Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

app.Config file

Status
Not open for further replies.

t16cag

Programmer
Joined
Mar 9, 2007
Messages
5
Location
GB
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top