You are currently offline, waiting for your internet to reconnect

How to use Isolated Storage in Silverlight 3

This article has been archived. It is offered "as is" and will no longer be updated.
This article describes an All-In-One Code Framework sample that is available for download. Isolated storage enables applications to create and maintain a safe client-side virtual file system for partial trust applications. In Silverlight, all I/O operations are restricted to isolated storage and do not use the file system of the operating system. This sample demonstrates how to utilize isolated storage to save and load bytes from isolated storage.  It also mentions how to improve the application performance by using BackgroundWorker.

Difficulty level

Download information

To download this code sample, click the following link:


Technical overview

  • How to store files to isolated storage?
    1. Use OpenFileDialog to get a local readable file stream.
    2. Get IsolatedStorageFile from application, and then use CreateFile method to get one writeable IsolatedStorageStream.
    3. Copy bytes from file stream to IsolatedStorageStream.
    4. Close stream.
How to store files to isolated storage?
Note: copy long stream is very time consuming, use BackgroundWorker to run it in other thread could get better performance. Details about BackgroundWorker, see
  • How does isolated storage treeview viewmodel works?
    1. Define entities for isolated storage virtual file and directory.
    2. In treeview, use HierarchicalDataTemplate to bind data to treeview node.
    3. When application starts, traverse isolated storage, use defined entity to create treeview viewmodel, and then set it as treeview's itemssource.
    Sample code:

    Entity definition(C#)

       // Isolatedstoarge file obj    public class IsoFile    {        public string FilePath{set;get;}        public string FileName { set; get; }        public Stream ContentStream        {            private set;            get;        }        public IsoFile(string filename, string path)        {            FileName = filename;            FilePath = path;        }    }    // Isolatedstorage directory obj    public class IsoDirectory:IsoFile    {        public ObservableCollection<IsoFile> Children        {             private set;            get;        }        public IsoDirectory(string filename,string path)            : base(filename,path)        {            Children = new ObservableCollection<IsoFile>();        }}
    Entity definition(

    ' Isolatedstoarge file objPublic Class IsoFile    Private _FilePath As String    Public Property FilePath() As String        Get            Return _FilePath        End Get        Set(ByVal value As String)            _FilePath = value        End Set    End Property    Private _FileName As String    Public Property FileName() As String        Get            Return _FileName        End Get        Set(ByVal value As String)            _FileName = value        End Set    End Property' Isolatedstorage directory objPublic Class IsoDirectory    Inherits IsoFile    Private _Children As ObservableCollection(Of IsoFile)    Public Property Children() As ObservableCollection(Of IsoFile)        Get            Return _Children        End Get        Private Set(ByVal value As ObservableCollection(Of IsoFile))            _Children = value        End Set    End Property    Public Sub New(ByVal filename As String, ByVal path As String)        MyBase.New(filename, path)        Children = New ObservableCollection(Of IsoFile)()    End SubEnd Class
    <controls:TreeView Name="tv1"

  • How to open and play media stream stored in isolated storage?
    1. Open isolated storage stream.
      IsolatedStorageFile _isofile = IsolatedStorageFile.GetUserStoreForApplication();       var stream = _isofile.OpenFile(item.FilePath, FileMode.Open, FileAccess.Read);
    2. Set it to MediaElement, then play.
  • How to use IsolatedStorageSetting to store config?

    IsolatedStorageSettings is a dictionary stored in isolated storage and maintained by Silverlight. It's a good place to store configuration.

        To store data to IsolatedStorageSetting for application usage, use
    IsolatedStorageSettings. ApplicationSettings["keyname"] = data;

        And if need store data for whole site usage, use
    IsolatedStorageSettings. SiteSettings["keyname"] = data;

  • Why directory depth should be less than 4 in application?

    Isolated storage limit the directory name to be less than 248 characters, and the full file path to be less than 260 characters. If create deeper directory, the path length would exceed the limitation. 

NoteFor more information about how to create the sample application and how to deploy the sample application, see the Readme.txt file that is included in the download package.

Technology category

  • Silverlight


This code sample contains the following programming language:
LanguageProject Name
Visual C#CSSL3IsolatedStorage
Visual Basic.NETVBSL3IsolatedStorage



  • IsolatedStorage, Silverlight

What is All-In-One Code Framework?

All-In-One Code Framework shows most Microsoft development techniques by using code samples in different programming languages. Each example is carefully selected, composed, and documented to show one common code scenario. For more information about All-In-One Code Framework, visit the following Web site:

How to find more All-In-One Code Framework samples

To find more All-In-One Code Framework samples, you can simply click the following link:

For more information, visit the following Web sites:

Isolated Storage

Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.

Article ID: 2127835 - Last Review: 12/12/2015 08:48:53 - Revision: 2.0

Microsoft Visual Studio 2008 Service Pack 1

  • kbnosurvey kbarchive kbcodefx kbrapidpub kbnomt atdownload kbsurveynew kbinfo KB2127835