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.

You might also like...

Comments

About the author

Graham Parker

Graham Parker United Kingdom

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 de...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are 10 types of people in the world, those who can read binary, and those who can't.”