Click here to Skip to main content
Click here to Skip to main content

Easily store form- and application-settings using Isolated Storage

, 26 Jan 2005
Rate this:
Please Sign up or sign in to vote.
A solution to easily store form- and application-settings using Isolated Storage.

Introduction

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.

Background

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

The 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:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <DemoText>CodeProject Rules!</DemoText>
  <DemoChecked>True</DemoChecked>
  <DemoCombo>4</DemoCombo>
  <Form1WindowState>0</Form1WindowState>
  <Form1>235,685,217,162</Form1>
</configuration>

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)
{
   config.Write("DemoText", txtDemo.Text);
   config.Write("DemoChecked", chkDemo.Checked.ToString());
   config.Write("DemoCombo", cmbDemo.SelectedIndex.ToString());
   config.WriteFormSettings(this);
   config.Persist();
}

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 = 
             GetConfigurationManager(Application.ProductName);
   config.ReadFormSettings(this);

   txtDemo.Text = config.Read("DemoText");
   chkDemo.Checked = config.ReadBoolean("DemoChecked", false);
   cmbDemo.SelectedIndex = config.ReadInteger("DemoCombo", 0);
}

Round-Up

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Edwin Roetman
Web Developer
Satellite Provider Satellite Provider
Since 1995 I have gathered wide experience in IT, in several different roles and in different environments. I am currently working for Capgemini Netherlands as Microsoft Software Developer, Software Architect and Project Manager.
In my leisure time I like to do sports, mainly speedskating and windsurfing. I also love to go cycling and to travel with my girlfriend and our son in camper.

Comments and Discussions

 
GeneralVb.Net Version Pinmemberr3xx0n2-Jun-11 7:15 
GeneralThanks a lot PinmemberMalisa Ncube13-Apr-10 7:01 
QuestionPlease could you provide me with VB.NET code of this project? PinmemberMember 39260143-Sep-09 20:27 
GeneralC++ version Pinmemberdkpeall7-Dec-08 8:56 
GeneralRe: C++ version PinmemberEdwin Roetman7-Dec-08 9:31 
GeneralOn request, VB.NET code is available. Pinmembermichaeltaylor10-Jul-08 5:31 
GeneralRe: On request, VB.NET code is available. PinmemberEdwin Roetman7-Dec-08 9:32 
GeneralRe: On request, VB.NET code is available. Pinmembermichaeltaylor9-Dec-08 8:44 
GeneralRe: On request, VB.NET code is available. PinmemberEdwin Roetman10-Dec-08 14:15 
GeneralSerialize an Array Pinmemberdgortemaker25-Jun-07 23:43 
GeneralRe: Serialize an Array PinmemberEdwin Roetman9-Jul-07 10:42 
GeneralLoosing settings PinmemberKnuckles9227-Mar-07 7:05 
GeneralRe: Loosing settings PinmemberEdwin Roetman27-Mar-07 12:18 
QuestionHow do you store data and configuration? PinmemberDewey Vozel4-Feb-05 3:47 
AnswerRe: How do you store data and configuration? Pinmembergxdata5-Feb-05 17:51 
GeneralRe: How do you store data and configuration? PinmemberDewey Vozel8-Feb-05 4:44 
AnswerRe: How do you store data and configuration? PinmemberErwyn van der Meer26-Feb-05 7:42 
AnswerRe: How do you store data and configuration? PinmemberKen Hadden18-Apr-07 11:18 
GeneralRe: How do you store data and configuration? PinmemberDewey Vozel18-Apr-07 13:54 
GeneralRe: How do you store data and configuration? PinmemberKen Hadden22-Apr-07 12:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411022.1 | Last Updated 26 Jan 2005
Article Copyright 2005 by Edwin Roetman
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid