(Difference between revisions)

File manipulation with IsolatedStorageFile on Windows Phone

From Nokia Developer Wiki
Jump to: navigation, search
somnathbanik (Talk | contribs)
(Somnathbanik -)
somnathbanik (Talk | contribs)
(Somnathbanik -)
Line 5: Line 5:
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|devices= WP7 Emulator  <!-- Devices tested against - e.g. ''devices=N95, N8'') -->
|devices= WP7 Emulator  <!-- Devices tested against - e.g. ''devices=N95, N8'') -->
|sdk= [http://www.developer.nokia.com/Develop/Windows_Phone/Tools/ Windows Phone SDK 7.1])
|sdk= [http://www.developer.nokia.com/Develop/Windows_Phone/Tools/ Windows Phone SDK 7.1]
|platform= WP7.1 <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
|platform= WP7.1 <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->

Revision as of 16:14, 18 November 2011

This article demonstrates how to store data locally on WP7 using Isolated Storage.

WP Metro Icon File.png
SignpostIcon XAML 40.png
WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata
Code ExampleTested with
Devices(s): WP7 Emulator
Keywords: File Handling/ Isolated Storage
Created: somnathbanik (18 Nov 2014)
Last edited: somnathbanik (18 Nov 2011)



Isolated Storage is used to store local data on a Windows Phone 7. There are two ways we can store data in Isolated Storage :

File Manipulation in WP7
WP7 Isolated Storage Explorer

Basic Idea

In this article we will use IsolatedStorageFileStream class to Read/Write/Create file in Isolated Storage. For our simplicity we will create an application that can take user data as input and save the data in a file in Isolated Storage, and also can retrieve the data from Isolated Storage.


When we are ready with an empty project for WP7, let’s take some data from user input and save it to a file in Isolated Storage.

IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication();
StreamWriter Writer = new StreamWriter(new IsolatedStorageFileStream("TestFile.txt", FileMode.OpenOrCreate, fileStorage));

We have created an object of IsolatedStorageFile which obtain a virtual storage for the application. Then let’s create a new StreamWriter, to write the file to the specified location. writeLine() is used to write the content to the file. And Finally we close the StreamWriter. This will just create a new file with the name TestFile.txt in the Isolated Storage.

To retrieve the content of the file from the Isolated Storage. Let’s again create a virtual store for the application. This time we will create a StreamReader to read the content.

IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication();
StreamReader Reader = null;
Reader = new StreamReader(new IsolatedStorageFileStream("TestFile.txt", FileMode.Open, fileStorage));
string textFile = Reader.ReadToEnd();
textBox2.Text = textFile;
MessageBox.Show("File it not created");

Then read the file from the specific location. Read the content of the file with ReadToEnd() and finally display the content of the file to the Textbox. If the file doesn’t exist and user clicks on the retrieve button to display the file content then we display a message. We can also check the file existence with IsolatedStorageFile::FileExists(FilePath).

Windows Phone 7 Isolated Storage Explorer

Windows Phone 7 Isolated Storage Explorer allows you to see and explore files in the Isolated Storage. You can also import/export the file to/from the Isolated Storage.

C:\Program Files\WP7 Isolated Storage Explorer\Library\IsolatedStorageExplorer.dll
  • Start IsolatedStorageExplorer in the App.xaml.cs while launching.
private void Application_Launching(object sender, LaunchingEventArgs e)

Localhost is the name/IP address of the system

  • In Activated event in App.xaml.cs call IsolatedStorageExplorer.Explorer.RestoreFromTombstone()
private void Application_Activated(object sender, ActivatedEventArgs e)
  • Run the application and launch the IsolatedStorageExplorer from

Start->All Programs-> WP7 Isolated Storage Explorer

  • This will display the file being created, you can download the file to the desktop, delete the file or even can import file to the Isolated Storage.


When we create a file in Isolated Storage the I/O operations are restricted to, so the data are local to the application. It doesn’t have direct access from any other file system or application. So it’s secure from unauthorized access. If you are sharing same data from two applications then those data can’t be local to any of the application, it suggested to store the data in cloud. The storage resources on a phone are limited, so it is recommended to store necessary data.

Source Code

The full source code of the example is available here: File:IsolatedStorageWP7.zip

1262 page views in the last 30 days.