A brief how-to on providing user settings in your application.

First, if you want to provide defaults, you want to add the following to the application’s configuration:


Notice there are two levels of the <add> tag, one is ‘global’ settings, the other is segregated off in a named section.

Reading this information is along the following lines:

			//reads the current user's settings
			UserSettingsSection settings = UserSettingsSection.UserSettings;
			//access a global setting:
			Assert.IsTrue(settings["a"] == "b");
			//access a setting from within the section "c"
			if(settings.Sections["c"] != null)
				Assert.IsTrue(settings.Sections["c"]["x"] == "y");

To update the information you need to perform the following:

			//Open the configuration
			Configuration cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
			UserSettingsSection settings = UserSettingsSection.UserSettingsFrom(cfg);
			//Push the settings in
			settings["a"] = "b";
			settings.Sections["c"] = new UserSettingsSubSection();
			settings.Sections["c"]["x"] = "y";
			//save the configuration

Get the source code or download binaries.