Friday, August 28, 2009

Isolated Storage

Isolated Storage - A private file system managed by the .NET Framework.

Why use it?
Isolated Storage provides a safe location, regardless of user access level, to store information that can be isolated by each user on the machine to store such things as user preferences.

How do I use it?
Here's an example where I store the height and width of a window in a text file on closing.
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly();
IsolatedStorageFileStream stream = new IsolatedStorageFileStream("pref.txt", FileMode.Create, isf);
StreamWriter sw = new StreamWriter(stream);
sw.WriteLine("Width:" + this.Width);
sw.WriteLine("Height:" + this.Height);
sw.Close();

Where did this text file actually get saved?
Well, on my machine (Vista) it went into C:\Users\[User]\AppData\Local\IsolatedStorage and then through 3 more cryptic folder names until it reached the AssemFiles folder where the "pref.txt" file showed up.

The location can change depending on the OS. See here for other OS locations.

More Info: Article: When and when not to use Isolated Storage