There are three ways an application can store data:
- Settings: Store data as key/value pairs by using the IsolatedStorageSettings class.
- Files and folders: Store files and folders by using the IsolatedStorageFile class.
- Relational data: Store relational data in a local database by using LINQ to SQL.
Isolated Storage Best Practices for Windows Phone
- When an application is updated in Windows Phone Marketplace, its isolated storage folder is not touched or modified.
- If an application is uninstalled, the data root and everything within the store, including the isolated storage folder, is deleted.
- Windows Phone applications are not restricted to a particular quota. When a Windows Phone has only 10 percent of its storage space remaining, the user receives a status notification.
- If your application creates any temporary data in isolated storage, make sure that it is cleared when the data is no longer being used. Consider creating a temporary cache folder that you can clear at regular intervals.
- If your application allows users to create data, they should have the option to delete the data that they create.
- synchronize or archive data to the cloud and keep only the most relevant data.
How to: Use the Isolated Storage Explorer Tool
Isolated Storage Explorer (ISETool.exe) is a command-line tool that installs with the Windows Phone SDK. You can use Isolated Storage Explorer to list, copy, and replace files and directories in isolated storage. Depending on your operating system, Isolated Storage Explorer is installed in one of following locations:Program Files\Microsoft SDKs\Windows Phone\v7.1\Tools\IsolatedStorageExplorerTool
Program Files (x86)\Microsoft SDKs\Windows Phone\v7.1\Tools\IsolatedStorageExplorerTool Isolated Storage Explorer has the following syntax:
ISETool.exe <ts|rs|EnumerateDevices|dir[:device-folder]> <xd|de|deviceindex[:n]> <Product GUID> [<desktop-path>]
Listing Files in Isolated Storage
ISETool.exe dir <xd|de> <Product GUID>
ISETool.exe dir <deviceindex:index> <xd|de> <Product GUID>
ISETool.exe dir:device-folder <xd|de> <Product GUID>
Copying Files in Isolated Storage
ISETool.exe ts <deviceindex:index> <xd|de> <Product GUID> <desktop-path> Replacing Filse in Isolated Storage
ISETool.exe rs <xd|de> <Product GUID> <desktop-path>
How to: Store Files and Folders for Windows Phone
This topic shows you how to perform the following isolated storage tasks in your application: Obtain a virtual store for an applicationIsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();Create a parent folder
myStore.CreateDirectory("MyFolder");Create and add text to an isolated storage file
using (var isoFileStream = new IsolatedStorageFileStream("MyFolder\\myFile.txt", FileMode.OpenOrCreate, myStore))Read the text placed in the storage file
{
//Write the data
using (var isoFileWriter = new StreamWriter(isoFileStream))
{
isoFileWriter.WriteLine(txtWrite.Text);
}
}
try
{
// Specify the file path and options.
using (var isoFileStream = new IsolatedStorageFileStream("MyFolder\\myFile.txt", FileMode.Open, myStore))
{
// Read the data.
using (var isoFileReader = new StreamReader(isoFileStream))
{
txtRead.Text = isoFileReader.ReadLine();
}
}
}
catch
{
// Handle the case when the user attempts to click the Read button first.
txtRead.Text = "Need to create directory and the file first.";
}
No comments:
Post a Comment