30 March 2011

Silverlight - Isolated Storage

When using Silverlight Isolated Storage, you have two options:

Application or site

Application
Storage specific to the application and the user using it.
Site
Storage shared between all applications in a domain for the user.

Read from IS

using System.IO.IsolatedStorage;
using(IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForSite()){
  if (storage.FileExists(IS_FILE_NAME)) {
    using(IsolatedStorageFileStream stream = new IsolatedStorageFileStream(IS_FILE_NAME, FileMode.Open, storage)){
      //Read the stream
    }
  }
}

Write to IS

using(IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForSite()){
  using(IsolatedStorageFileStream stream = new IsolatedStorageFileStream(IS_FILE_NAME, FileMode.OpenOrCreate, storage)){
    stream.WriteLine("EGS rules!");
  }
}

No comments:

Post a Comment