Library tutorials & articles

Isolated Storage in .NET

Isolated Storage

When it comes to per-user information you can follow a couple of different paths. Either you can develop your own ad-hoc routines to store user settings and other information in various places or you can consider Isolated Storage.

Isolated storage is a special area on the hard drive that your application knows how to find. The clever thing is that your application can’t see the physical path location (this is managed by the .NET framework). What’s more your application doesn’t need permission to write to the hard drive – so this technique is suitable for .NET applications that are running in a restricted security mode. Only the User and Assembly that creates the storage can have access to it. If your corporate environment has been designed to support hot-desking then Isolated Storage also supports roaming profiles

In essence Isolated Storage is a well thought out viable storage area that you can take advantage of when you’re considering your storage options. Isolated Storage Classes live in the System.IO Namespace and consist of a Store (the storage area) which has methods to create directories and read files and you can read and write to the area using Streams.

You could write a DataSet into Isolated Storage simply using the following code:

IsolatedStorageFile storeWrite = IsolatedStorageFile.GetUserStoreForDomain();
IsolatedStorageFileStream streamWrite = new IsolatedStorageFileStream("MyXML.xml", FileMode.Create, storeWrite);
myDataSet.WriteXml(streamWrite,XmlWriteMode.WriteSchema);
streamWrite.Close();
storeWrite.Dispose();
this.Close();

In order to read it back again, you could do the following:

IsolatedStorageFile storeRead = IsolatedStorageFile.GetUserStoreForDomain();
IsolatedStorageFileStream streamRead = new IsolatedStorageFileStream("MyXML.xml", FileMode.Open, storeRead);
myDataSet.ReadXml(streamRead,XmlReadMode.ReadSchema);
streamRead.Close();
storeRead.Dispose();

There is a command line utility storeadm.exe which you can use to manually view Isolated Storage and help debug applications that make use of isolated storage. And the Isolation provided can be either configured so that the storage area cannot be shared across components in different applications, or it can be configured so that it can be shared across components in different applications. The flexibility is down to you.

For more information visit http://www.a9.com/ (you may not use Google again) and search for Isolated Storage.

Comments

  1. 10 Dec 2004 at 04:06

    NiceIntro into another viable storage solution.


    Thanks

  2. 01 Jan 1999 at 00:00

    This thread is for discussions of Isolated Storage in .NET.

Leave a comment

Sign in or Join us (it's free).

Graham Parker Graham Parker is a co-founder and principal of DevTrain and spends his time consulting, developing and training. He is one of a handful of MVP's in Visual Basic around the world, and has been devel...
AddThis

Related discussion

Related podcasts

  • More jQuery in ASP.NET

    In this episode Chris Brandsma, Rick Strahl, Dave Ward, Bertrand Le Roy, and Scott Koon conclude their discussion of Microsoft's jQuery in ASP.NET announcement1.This episode of the Alt.NET Podcast is brought to you by LLBLGen Pro, the most mature O/R mapper and code generator out there.Are ...

Events coming up

  • Nov 18

    15 Minutes of Fame

    Dresher, United States

    This is a yearly tradition. We select 10 of the favorite speakers from monthly meetings, code camps, and hands on labs. Each one does a 15 minute talk on their favorite .NET technology. This is our 10th anniversary so we plan a gala event with special prizes and refreshments.

We'd love to hear what you think! Submit ideas or give us feedback