How to Use Isolated Storage in Your WP7 Application

The Windows Phone platform does not allow traditional file access for data storage. Windows Phone developers need to be aware of Isolated storage, which provides managed applications the ability to create and maintain local storage.


Silverlight based Windows Phone applications come with the limitations of the Silverlight development platform, which means no direct local file access. In such scenarios, application developers have to resort to using what the Silverlight platform provides for data storage access. Before we dig deeper, we need to understand that I/O operations in Silverlight are restricted to only isolated storage for user code (as opposed to platform code, which is written by Microsoft). This prevents security issues and prevents unauthorized data access.

Isolated Storage APIs

Silverlight for Windows Phone provides the isolated storage facility via the APIs in the System.IO.IsolatedStorage namespace. Let us look at the various APIs we can use.


This class represents an isolated storage area. The main difference between the Windows Phone version and the Silverlight version is that the Windows Phone platform's version does not have the API for getting the user store "GetUserStoreForSite". Another difference is that the quota for Windows Phone application is unlimited.


This class provides the ability to store user specific data as key-value pairs in an IsolatedStorageFile. The SiteSettings property is not available on the Windows Phone platform.


System.IO.IsolatedStorage.IsolatedFileStream provides a file stream access to a file stored within isolated storage.


Let us explore creating a Windows Phone application that utilizes Isolated Storage for writing and reading application data.

Create a new "Silverlight for Windows Phone" application called "WindowsPhoneIsolatedStorageDemo".

Create a new Silverlight for Windows Phone application
Figure 1: Create a new "Silverlight for Windows Phone" application

Go to the code-behind of the MainPage.xaml and add the reference to the System.IO.IsolatedStorage namespace.

// MainPage.xaml.cs


Add a button and a textbox on the page.

Add an event handler for the button's click event. In this event handler, we will create (if it does not already exist) a directory called "MyStorageLocation". In this function, we will create a file called mytext.txt and save the contents of the text.

private void buttonSave_Click(object sender, RoutedEventArgs e)
		if (!myISOStore.DirectoryExists("MyStorageLocation"))

			StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream(@"MyStorageLocation\mytext.txt", FileMode.OpenOrCreate, myISOStore));



Now, we create an event handler for the page load event. In this function, we will check if a directory called "MyStorageLocation" already exists in the isolated storage. If it exists, we will open the "mytext.txt" file and fill the textbox with the contents of the file.

private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
		if (myISOStore.DirectoryExists("MyStorageLocation"))
			StreamReader readerFile = new StreamReader(new IsolatedStorageFileStream(@"MyStorageLocation\mytext.txt", FileMode.Open, myISOStore));
			textBoxValue.Text = readerFile.ReadLine();


Now, compile and run the application.

The first time we run the application, the text box is empty. Now type something in the textbox and click Save.

Stop the application. Restart the application. Now when the application starts for the second time, we find that the textbox contains the contents we typed during the last run of the application. We see that the information was stored in an isolated storage location and we have used the IsolatedStorage APIs to extract the data.


In this article, we saw how to use Isolated Storage for application data storage. I hope that you have learned how to make your Windows Phone applications use Isolated Storage.

About the Author

Vipul Vipul Patel

Vipul Patel is a Software Engineer currently working at Microsoft Corporation, working in the Office Communications Group and has worked in the .NET team earlier in the Base Class libraries and the Debugging and Profiling team. He can be reached at

Related Articles



  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Hurricane Sandy was one of the most destructive natural disasters that the United States has ever experienced. Read this success story to learn how Datto protected its partners and their customers with proactive business continuity planning, heroic employee efforts, and the right mix of technology and support. With storm surges over 12 feet, winds that exceeded 90 mph, and a diameter spanning more than 900 miles, Sandy resulted in power outages to approximately 7.5 million people, and caused an estimated $50 …

  • Download the Information Governance Survey Benchmark Report to gain insights that can help you further establish business value in your Records and Information Management (RIM) program and across your entire organization. Discover how your peers in the industry are dealing with this evolving information lifecycle management environment and uncover key insights such as: 87% of organizations surveyed have a RIM program in place 8% measure compliance 64% cannot get employees to "let go" of information for …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds