WP7到WP8.1应用程序更新。 WP8.1 ApplicationData是否会访问使用WP7 IsolatedStorageFile存储的相同数据?

时间:2016-10-13 21:42:28

标签: windows-phone-7 windows-phone-8

我有一个Windows Phone 7应用程序,已经在商店里存在多年了。它安装在WP 7.x,8.0和8.1设备上。我正在将应用程序转换为目标WP8.1,因此我可以使用较新的Microsoft AdControl(旧版本将在年底停止投放广告)。这意味着我需要开始使用ApplicationData.Current.LocalFolder来读/写数据,而不是使用旧的IsolatedStorageFile.GetUserStoreForApplication()。

我的用户使用IsolatedStorageFile.GetUserStoreForApplication()存储了大量数据。如果他们将应用程序升级到WP8.1版本,我想确保他们不会丢失任何这些数据,并且仍然可以使用ApplicationData.Current.LocalFolder访问数据。

任何人都可以确认是这种情况吗?

这就是我在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");
        }
    }
}

这就是我将如何阅读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
    }
}

1 个答案:

答案 0 :(得分:3)

Windows Phone 7应用,使用独立存储:

var store = IsolatedStorageFile.GetUserStoreForApplication();

Windows 8.1 / UWP app:

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

两者都会产生相同的文件夹。绝对路径不同:

  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”
  3. 但两条路径将共享相同的文件夹/文件。最重要的是编辑 Package.appxmanifest XML。在Visual Studio中,单击“查看代码”上的鼠标右键(不要通过“ View Designer ”打开)。在此XML中,您必须编辑此行:

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

    PhoneProductId 替换为旧版WP7应用的ID, PhonePublisherId 替换旧的 PublisherId (来自旧的WP7应用)。如果你不这样做,那些代码会给你不同的文件夹(WP 8.1 / UWP代码给你空文件夹)。但是,使用此更改的ID,您将收到包含所有旧数据的相同文件夹。

    新应用将在安装后替换旧应用。

相关问题