How to Modify applicationSettings section

Problem

My.Settings.YourSettingName is a read only property for application scope configuration

Explanation

By design you can’t modify application scope configuration settings, e.g. My.Settings.Setting1 is always read-only.

Solution

You can change the scope of the setting from Application to User, but then the setting will be stored in user.config instead of app.config
Another solution is to access application configuration file directly via System.Configuration.Configuration class. Here a small sample that updates LastDownloadDate configuration setting inside applicationSettings/APP.My.MySettings section:

Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
Dim sec As ClientSettingsSection = config.GetSection("applicationSettings/APP.My.MySettings")
sec.Settings.Get("LastDownloadDate").Value.ValueXml.InnerXml = Now.ToString
sec.SectionInformation.ForceSave = True
config.Save(ConfigurationSaveMode.Modified)

One thought on “How to Modify applicationSettings section”

  1. That is a great idea. Often I find myself wneinrdog why something’s doing something I don’t expect and it’s only an hour later when I realise it has been configured at a bizarre scope! (Quite often by myself and I’d just forgotten! ).

Leave a Reply to Navneet Cancel reply

Your email address will not be published. Required fields are marked *