[英]WP7 to WP8.1 app update. Will WP8.1 ApplicationData access same data that was stored using WP7 IsolatedStorageFile?
我有一个Windows Phone 7应用程序,该应用程序已经存在很多年了。 它安装在WP 7.x,8.0和8.1设备上。 我正在将该应用程序转换为WP8.1目标,因此我可以使用较新的Microsoft AdControl(旧的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
}
}
Windows Phone 7应用程序,使用隔离存储:
var store = IsolatedStorageFile.GetUserStoreForApplication();
Windows 8.1 / UWP应用:
var localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
两者将导致在同一文件夹中。 绝对路径不同:
但两个路径都将在其中共享相同的文件夹/文件。 最重要的是编辑Package.appxmanifest XML。 在Visual Studio中,通过鼠标右键单击“ 视图代码 ”(不要通过“ 视图设计器 ”打开)。 在此XML中,您必须编辑以下行:
<mp:PhoneIdentity PhoneProductId="NEW_APP_ID" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
由旧WP7应用程序和PhonePublisherId的ID,由旧的publisherId更换PhoneProductId(从旧WP7应用程序也是如此)。 如果不这样做,该代码将为您提供不同的文件夹(WP 8.1 / UWP代码为您提供空文件夹)。 但是,通过更改此ID,您将收到包含所有旧数据的相同文件夹。
安装后,新应用将替换您的旧应用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.