In other languages

Namespaces

Variants

Views

Actions

Search

Contents

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

{{Abstract|This code example demonstrates how to store files locally using Windows Phone Isolated Storage.}} Official documentation on the topic(s) is available here: [http://msdn.microsoft.com/en-us/library/ff626522(v&#61;vs.92).aspx Local Data Storage for Windows Phone] (MSDN).

{{Abstract|This code example demonstrates how to store files locally using Windows Phone Isolated Storage.}} Official documentation on the topic(s) is available here: [http://msdn.microsoft.com/en-us/library/ff626522(v&#61;vs.92).aspx Local Data Storage for Windows Phone] (MSDN).

Line 45:

Line 46:

Writer.Close();

Writer.Close();

</code>

</code>

−

We have created an object of [http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile.aspx IsolatedStorageFile] which obtain a virtual storage for the application. Then let’s create a new [http://msdn.microsoft.com/en-us/library/system.io.streamwriter(v=VS.95).aspx StreamWriter], to write the file to the specified location. {{Icode|WriteLine()}} is used to write the content to the file. And Finally we close the [http://msdn.microsoft.com/en-us/library/system.io.streamwriter(v=VS.95).aspx StreamWriter]. This will just create a new file with the name '''TestFile.txt''' in the Isolated Storage.

+

We have created an object of [http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile.aspx IsolatedStorageFile] which obtain a virtual storage for the application. Then let’s create a new [http://msdn.microsoft.com/en-us/library/system.io.streamwriter(v=VS.95).aspx StreamWriter], to write the file to the specified location. {{Icode|WriteLine()}} is used to write the content to the file. And Finally we close the [http://msdn.microsoft.com/en-us/library/system.io.streamwriter(v=VS.95).aspx 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 [http://msdn.microsoft.com/en-us/library/system.io.streamreader(v=VS.95).aspx StreamReader] to read the content.

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 [http://msdn.microsoft.com/en-us/library/system.io.streamreader(v=VS.95).aspx StreamReader] to read the content.

Revision as of 16:22, 3 August 2013

This code example demonstrates how to store files locally using Windows Phone Isolated Storage. Official documentation on the topic(s) is available here: Local Data Storage for Windows Phone (MSDN).

Note: Symbian developers will recognise that Isolated Storage is conceptually similar to an app's private data cage. The main difference is that Windows Phone apps only have access to their own isolated storage - there is no shared file system. This creates challenges for apps that want to share data or files.

This code examples uses IsolatedStorageFileStream class to write and retrieve text (provided by the user) to a file. In a following section, we also provide information about Isolated Storage Explorer, a tool for exploring the file structure in isolated storage.

File Manipulation in WP7

Implementation

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

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.

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

WP7 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.

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.

Summary

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.