In this article we are going to learn about the storage in windows phone, it will be a local data storage and we will see different methods to use it. Let’s get a quick overview about how the data is stored locally in a windows phone.
There are two different locations in which the data is stored:
- Installation Folder – This is the place from where the application gets all its item to the phone, it is also referred as App Data folder. This is ready only folder where we can just read the files which are required for installation and we cannot perform any writing operation.
- Local Folder – It is formerly known as Isolated Storage, here we can perform both read and write operations, this is the place we are going to spend our most of the time.
There are different methods for addressing storage location:
File Type / API
|Local Database Data Context||appdata:/||isostore:/||MyDataContext db =
|File access using WP7.1 Isolated Storage API||Not supported||StorageFile and StorageFolder APIs||var isf =IsolatedStorageFile.
|File access using Windows.Storage APIs via URIs||ms-appx:///||ms-appdata:///local/||StorageFile storageFile = await Windows.Storage.StorageFile.
|File access using Windows.Storage APIs via StorageFolder Refrence||Windows.Application
|var localFolder = Windows.Storage.ApplicationData.
storageFile = await localFolder.GetFileAsync
Windows Phone 8 File Access Alternatives
Let’s have a look at getting a reference of a file by three different ways.
- WP7.1 Isolated Storage APIs
var isf = IsolatedStorageFile.GetUserStoreForApplication(); IsolatedStorageFileStream fs = new IsolatedStorageFileStream("CaptainsLog.Store", FileMode.Open, isf);
- WP8 Storage APIs using URI
StorageFile storageFile = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appdata:///local/CaptainsLog.store"));
- WP8 Storage APIs
Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; Windows.Storage.StorageFile storageFile = localFolder.GetFileAsync("CaptainsLog.store");
So, now we are aware of different type of file handing techniques, in the coming posts we will learn how to use them individually.