Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 30,744 times

Contents

Related Categories

Isolated Storage in .NET - Isolated Storage

grahamp

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.

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 developing using Visual Basic since 1993. Graham was a founding member of VBUG in 1994, and held the role of Chairman of the group until March 2005. Graham is a frequent speaker at technical conferences and has presented on a number of different topics to diverse audiences including VBITS, VBUG, the Access User Group and the British Computer Society. In addition to working in the IT industry since 1985, Graham holds a BSc Honours degree in Applied Computer Systems from Brunel University.

Comments