Search code examples
windows-phone-7windows-phone-8

WP7 to WP8.1 app update. Will WP8.1 ApplicationData access same data that was stored using WP7 IsolatedStorageFile?


I have a Windows Phone 7 app that has been in the store for many years now. It is installed on WP 7.x, 8.0, and 8.1 devices. I am converting the app to target WP8.1, so I can use the newer Microsoft AdControl (The old one will stop serving ads at the end of the year). This means I will need to start using ApplicationData.Current.LocalFolder to read/write data, instead of using the old IsolatedStorageFile.GetUserStoreForApplication().

My users have lots of data that has been stored using IsolatedStorageFile.GetUserStoreForApplication(). If they upgrade the app to the WP8.1 version, I want to be sure that they will not lose any of this data and that the data will still be accessible using ApplicationData.Current.LocalFolder.

Can anyone confirm that this is the case?

This is how I wrote data in WP7:

using (IsolatedStorageFile applicationStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
    using (IsolatedStorageFileStream file = applicationStorage.OpenFile(filename, FileMode.Create, FileAccess.Write))
    {
        using (StreamWriter sw = new StreamWriter(file))
        {
            sw.WriteLine("some data goes here");
        }
    }
}

This is how I will be reading data in WP8.1:

using (Stream stream = await ApplicationData.Current.LocalFolder.OpenStreamForReadAsync(filename))
{
    using (StreamReader sr = new StreamReader(stream))
    {
        String line = sr.ReadLine();
        // Do something with line
    }
}

Solution

  • Windows Phone 7 app, using Isolated Storage:

    var store = IsolatedStorageFile.GetUserStoreForApplication();
    

    Windows 8.1/UWP app:

    var localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
    

    both will result in the same folder. Absolute path is different:

    1. WP7 IS: "C:\Data\Users\DefApps\AppData\{YOUR_APP_ID}\local"
    2. WP 8.1 / UWP: "C:\Data\Users\DefApps\AppData\Local\Packages\YOURCOMPANY.YOURAPP_SOMEHASH\LocalState"

    but both paths will share the same folder / files inside. The most important thing is to edit Package.appxmanifest XML. In Visual Studio click by right mouse button on"View Code" (do not open by "View Designer"). In this XML you have to edit this row:

    <mp:PhoneIdentity PhoneProductId="NEW_APP_ID" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
    

    Replace PhoneProductId by Id of your old WP7 App and PhonePublisherId by your old PublisherId (from old WP7 App too). If you do not do this, that codes will give you different folders (WP 8.1 / UWP code gives you empty folder). However, with this changed Ids you will receive the same folder with all old data.

    New app will replace your old app after installation.