Click here to Skip to main content
11,431,011 members (68,872 online)
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 Pin
r3xx0n2-Jun-11 7:15
memberr3xx0n2-Jun-11 7:15 
GeneralThanks a lot Pin
Malisa Ncube13-Apr-10 7:01
memberMalisa Ncube13-Apr-10 7:01 
QuestionPlease could you provide me with VB.NET code of this project? Pin
Member 39260143-Sep-09 20:27
memberMember 39260143-Sep-09 20:27 
GeneralC++ version Pin
dkpeall7-Dec-08 8:56
memberdkpeall7-Dec-08 8:56 
GeneralRe: C++ version Pin
Edwin Roetman7-Dec-08 9:31
memberEdwin Roetman7-Dec-08 9:31 
GeneralOn request, VB.NET code is available. Pin
michaeltaylor10-Jul-08 5:31
membermichaeltaylor10-Jul-08 5:31 
GeneralRe: On request, VB.NET code is available. Pin
Edwin Roetman7-Dec-08 9:32
memberEdwin Roetman7-Dec-08 9:32 
GeneralRe: On request, VB.NET code is available. Pin
michaeltaylor9-Dec-08 8:44
membermichaeltaylor9-Dec-08 8:44 
GeneralRe: On request, VB.NET code is available. Pin
Edwin Roetman10-Dec-08 14:15
memberEdwin Roetman10-Dec-08 14:15 
GeneralSerialize an Array Pin
dgortemaker25-Jun-07 23:43
memberdgortemaker25-Jun-07 23:43 
GeneralRe: Serialize an Array Pin
Edwin Roetman9-Jul-07 10:42
memberEdwin Roetman9-Jul-07 10:42 
GeneralLoosing settings Pin
Knuckles9227-Mar-07 7:05
memberKnuckles9227-Mar-07 7:05 
GeneralRe: Loosing settings Pin
Edwin Roetman27-Mar-07 12:18
memberEdwin Roetman27-Mar-07 12:18 
QuestionHow do you store data and configuration? Pin
Dewey Vozel4-Feb-05 3:47
memberDewey Vozel4-Feb-05 3:47 
AnswerRe: How do you store data and configuration? Pin
gxdata5-Feb-05 17:51
membergxdata5-Feb-05 17:51 
GeneralRe: How do you store data and configuration? Pin
Dewey Vozel8-Feb-05 4:44
memberDewey Vozel8-Feb-05 4:44 
AnswerRe: How do you store data and configuration? Pin
Erwyn van der Meer26-Feb-05 7:42
memberErwyn van der Meer26-Feb-05 7:42 
AnswerRe: How do you store data and configuration? Pin
Ken Hadden18-Apr-07 11:18
memberKen Hadden18-Apr-07 11:18 
GeneralRe: How do you store data and configuration? Pin
Dewey Vozel18-Apr-07 13:54
memberDewey Vozel18-Apr-07 13:54 
GeneralRe: How do you store data and configuration? Pin
Ken Hadden22-Apr-07 12:37
memberKen 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
Web01 | 2.8.150428.2 | Last Updated 26 Jan 2005
Article Copyright 2005 by Edwin Roetman
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid