Posts Tagged ‘microsoft .net’

May 17
Written by andi | 1,564 views 3 Comments »

Modify app.config files

This tutorial will help you to change the values <appSettings> when you are deploying the application. Maybe we need to set application configuration parameters because we change our database to another server. This is code snippet to do it.

[code lang="vbnet"]
Private Sub ChangeAppSettings(ByVal KeyName As String, ByVal KeyValue As String)
Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
config.AppSettings.Settings(KeyName).Value = KeyValue
config.Save(ConfigurationSaveMode.Modified)
ConfigurationManager.RefreshSection(&quot;appSettings&quot;)
End Sub
[/code]