2016-10-13 65 views
0

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

我的用户有很多使用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 
    } 
} 

回答

3

Windows Phone 7的应用程序,:

var store = IsolatedStorageFile.GetUserStoreForApplication(); 

的Windows 8.1/UWP应用:

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

两者都会导致相同的文件夹。绝对路径是不同的:

  1. WP7是: “C:\数据\用户\ DefApps \应用程序数据\ {YOUR_APP_ID} \本地”
  2. WP 8.1/UWP:“C:\数据\ Users \用户DefApps \ AppData \ Local \ Packages \ YOURCOMPANY.YOURAPP_SOMEHASH \ LocalState“

但两个路径将共享相同的文件夹/文件里面。最重要的是编辑Package.appxmanifest XML。在Visual Studio中,单击鼠标右键“查看代码”(不要通过“查看设计器”打开)。在这个XML,你必须编辑此行:

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

由旧的publisherId由旧WP7应用程序的Id和PhonePublisherId更换PhoneProductId(从旧WP7应用程序也是如此)。如果你不这样做,该代码会给你不同的文件夹(WP 8.1/UWP代码给你空的文件夹)。但是,使用此更改的ID,您将收到包含所有旧数据的相同文件夹。

安装后,新的应用程序将替换您的旧应用程序。

+0

感谢GeoIT,特别是关于PhoneProductId的额外部分。 – Jared