The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
Isolated storage is a means of saving user-specific data, like saving to the registry or to the good-old .ini-files. To be able to easily use Isolated Storage, I have created a small class that handles writing form-settings (position and size) and application-settings (e.g. user preferences) with a simple interface.
The concept of Isolated Storage is well-described in these articles: Isolated Storage in .NET to store application data and Introduction to Isolated Storage.
The IsolatedStorage.ConfigurationManager class
IsolatedStorage.ConfigurationManager class handles reading and writing Isolated Storage. It has the following features:
- All settings are saved in XML files.
- The XML files have the same name as the application but with .config-extension (example: IsoStorageDemoCS.config).
- Form settings are saved by the name of the form.
- Settings saved by form are position, state and size.
- Other settings can be saved by using a unique name per setting.
Here’s an example of a settings file:
The interface of the class is explained in the following sections.
Save settings using the IsolatedStorage.ConfigurationManager class
To save settings, two calls are sufficient. First create an
IsolatedStorage.ConfigurationManager and then call the appropriate
Write-method. Here's a code sample:
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
Retrieve settings using the IsolatedStorage.ConfigurationManager class
Retrieving settings is just as simple as saving:
private void Form1_Load(object sender, System.EventArgs e)
IsolatedStorage.ConfigurationManager config =
txtDemo.Text = config.Read("DemoText");
chkDemo.Checked = config.ReadBoolean("DemoChecked", false);
cmbDemo.SelectedIndex = config.ReadInteger("DemoCombo", 0);
Using Isolated Storage to store settings can be done very easily. The included demo-project gives a good example. On request, VB.NET code is available.