Silverlight: Isolated Storage Locations and Sizes

15. April 2011 08:35 by Mrojas in General  //  Tags: , , , , ,   //   Comments (0)

The actual Isolated Storage location is fixed but depends on the operating system where the Silverlight application is running:

From: http://msdn.microsoft.com/en-us/library/3ak841sy.aspx#isolated_storage_locations

Operating system

Location in file system

Windows 98, Windows Me - user profiles not enabled

Roaming-enabled stores =
<SYSTEMROOT>\Application Data
Non Roaming stores = WINDOWS\Local Settings\Application Data

Windows 98, Windows Me - user profiles enabled

Roaming-enabled stores =
<SYSTEMROOT>\Profiles\<user>\Application Data
Non roaming stores = Windows\Local Settings\Application Data

Windows NT 4.0

<SYSTEMROOT>\Profiles\<user>\Application Data

Windows NT 4.0 - Service Pack 4

Roaming-enabled stores =
<SYSTEMROOT>\Profiles\<user>\Application Data
Non roaming stores =
<SYSTEMROOT>\Profiles\<user>\Local Settings\Application Data

Windows 2000, Windows XP, Windows Server 2003 - upgrade from Windows NT 4.0

Roaming-enabled stores =
<SYSTEMROOT>\Profiles\<user>\Application Data
Non roaming stores =
<SYSTEMROOT>\Profiles\<user>\Local Settings\Application Data

Windows 2000 - clean installation (and upgrades from Windows 98 and Windows NT 3.51)

Roaming-enabled stores =
<SYSTEMDRIVE>\Documents and Settings\<user>\Application Data
Non roaming stores =
<SYSTEMDRIVE>\Documents and Settings\<user>\Local Settings\Application Data

Windows XP, Windows Server 2003 - clean installation (and upgrades from Windows 2000 and Windows 98)

Roaming-enabled stores =
<SYSTEMDRIVE>\Documents and Settings\<user>\Application Data
Non roaming stores =
<SYSTEMDRIVE>\Documents and Settings\<user>\Local Settings\Application Data

Windows Vista

Roaming-enabled stores =
<SYSTEMDRIVE>\Users\<user>\AppData\Roaming
Non roaming stores =
<SYSTEMDRIVE>\Users\<user>\AppData\Local

 

The amount of data that you can put on the isolated storage is limited by the UserQuota property.

By default an application has 1MB of storage space.
(see http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile.increasequotato(VS.95).aspx)


If more space is needed the user can call the method increaseQuotaTo() that will allow prompting the user for permision to increase the amount of storage.

This will show a prompt dialog like:

To define policies I recommed looked at the Group Policy settings page
http://www.microsoft.com/GetSilverlight/resources/documentation/grouppolicysettings.aspx#isolated-storage and we might see more details about that in another post.

Silverlight and what to do with Application or User Settings or INI files

Some people ofter forget about this (even me Confused smile ) So that;’s why I’m posting about this.

In my work (at Artinsoft) we are currently performing a lot of Winforms and VB6 
migration to Silverlight. And a common problem is “What can I do with the user settings!!!”.

In VB6 you had your INI files and in Winforms you probably used something like the App settings.
But when you move to Silverlight what can you do!.
You need a set of initial values and you probably wont want to “burn” those inicial values in your XAP file.
It would be nicer if those values can just be set in the Web.Config file.

So a common way to solve this, is develop a simple helper class. This helper class will use a service that will
collect your initial ini files or appsettings values and store them in your Isolated Storage.
You can even use some kind of basic cryptography if you feel that your date is sensitive.

And then you can use the helpful IsolatedStorageSettings class. For example see this code,
that I borrowed from this post: http://wildermuth.com/2008/10/21/Using_Isolated_Storage_Settings_in_Silverlight_2

const string FAVCOLORNAME = "favoriteColor";
public Color? FavoriteColor
{
  get
  {
    if (IsolatedStorageSettings.ApplicationSettings[FAVCOLORNAME] != null)
    {
      Color? colorSetting =         IsolatedStorageSettings.ApplicationSettings[FAVCOLORNAME] as Color?;
      if (colorSetting != null) return colorSetting;
    }

    // If we can't find a favorite color, return a null color
    return new Color?();
  }
  set
  {
    IsolatedStorageSettings.ApplicationSettings[FAVCOLORNAME] = value;
  }
}

As you can see is very easy to save and recover simple settings from the Silverlight Isolated Storage