In an earlier blog post I explained how to populate a Windows forms ComboBox with settings stored in an App.config file. It’s easy to read settings from an App.config file and it’s just as easy to save application settings to configuration files as well.
You’ll need to define any settings you wish to retrieve and preserve in the project’s Settings.settings file. These property settings will be automatically transferred to the solution’s App.config file. To save the application’s settings during runtime, simply assign a property its new value and call the Save() method. Here’s an example:
Properties.Settings.Default.MainFormHeight = this.Height; Properties.Settings.Default.Save();This code would appear in a method that gets called in response to some application event, perhaps when a user selects a menu item to manually save application settings or when the application exits. When a user first executes an application that utilizes settings, the settings will be read from the application’s configuration file that resides in the working directory. This is the directory from which the application is launched. Application settings are saved in a location unique to each user. For example, an application named MyApp would have its user-specific configuration file saved to a location in the user’s AppData folder. A typical path would be:
C:\Users\username\AppData\Local\MyApp\MyApp.exe_Url_hiunsunuyggzq879b7spbgg6\assembly-version-numberIn this way, multiple users of the same application have their individual application settings preserved.