Isolated Storage

Say you want that every user save her preferences, last actions, last login time, etc. in her PC, where would you put that information? In isolated storage of course, this is like a .NET managed folder where you can create a number of files, there is one store per user/application/assembly, and the use couldn't be simpler:

IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForDomain();

IsolatedStorageFileStream archivo = new IsolatedStorageFileStream("personal.txt", System.IO.FileMode.Create, store);

StreamWriter writer = new StreamWriter(archivo);

writer.WriteLine("Some info valid only for this user and app domain");

writer.Close();

Later (or the next day) the user can retrieve the information like so:

IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForDomain();

IsolatedStorageFileStream archivo = new IsolatedStorageFileStream("personal.txt", System.IO.FileMode.Open, store);

StreamReader reader = new StreamReader(archivo);

string linea = reader.ReadLine();

reader.Close();

this.label1.Text = linea;

A user needs fewer rights for writing/reading isolated storage than for the standard filesystem which is a good security thing. On the other hand, you shouldn't put any sensitive information there, because is not hard to find it. Happy isolated storaging!

No Comments