Changing application settings programmatically in .NET Framework 2.0

As I promised to provide a component to enable you to change the values of the application-scope settings in .NET Framework 2.0, I'm now providing it.

It's a very simple dll written by C#, you can find the Source code here.

To use this dll you will need to get instance from the SettingWriter class as following

ApplicationSettingsWriter.SettingsWriter writer = new ApplicationSettingsWriter.SettingsWriter();

Then use the indexes of this object to change the value of the settings like this

writer["sampleSettings"] = "Omar";

In this example, "sampleSettings" is the key of the setting in the app.config. In Visual Studio 2005, you can access your settings visual by opening the properties window of the project (see figure below).

Writing the previous line indeed changes the value of the app.config but if you tried this line to retrieve the value, you wouldn't get your change

MessageBox.Show(Properties.Settings.Default.sampleSettings);

That's because .NET Framework loads the application settings with the loading of the application domain and caches them for performance. If you need to update this cache, you need to call the Reloud() method as following

Properties.Settings.Default.Reload();

You can download the binary from here and the source code from here.

Best regards,

Mohamed