I am currently working on a WPF/.Net project,
In this project the user has the choice to change the the skinning of the app entirely,
I am trying to write those settings after submission using configurations management,
but I don’t seem to be able to add the new values to the app.config file, here is my method underneath
Public Sub SetApplicationSetting(pstrAppSettingName As String, pstrAppSettingValue As String)
Dim lobjconfig As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
lobjconfig.AppSettings.Settings.Add(pstrAppSettingName, pstrAppSettingValue)
lobjconfig.Save(ConfigurationSaveMode.Full)
ConfigurationManager.RefreshSection("appSettings")
End Sub
any ideas?
Now the word on the street is that I cant Add to what is already there, So I thougth maybe I should remove it first before updating,
but still nothing, here is the new code
Dim lobjconfig As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
lobjconfig.AppSettings.Settings.Remove(pstrAppSettingName)
lobjconfig.AppSettings.Settings.Add(pstrAppSettingName, pstrAppSettingValue)
lobjconfig.AppSettings.Settings.CurrentConfiguration.Save()
lobjconfig.Save(ConfigurationSaveMode.Full, True)
ConfigurationManager.RefreshSection("appSettings")
My guess is that you are trying to change the configuration for all users (
ConfigurationUserLevel.None) and that you might not have the right to do so. I’d expect an exception when that fails, and you didn’t say one was thrown, so I might be on the wrong track.To find the culprit, you might try
ConfigurationUserLevel.PerUserRoamingAndLocalorConfigurationUserLevel.PerUserRoamingand see if that works better.Alternatively, but I doubt it makes a difference, you can make getting the configuration from a certain location specifically by using the following line: