0
我将数据保存在隔离存储器中,但是当我重新启动手机时,我无法从此处读取此数据。隔离存储空置。为什么?WP7将数据保存在隔离存储器中
如果我不关闭手机中的所有工作确定
这是我的代码:
using (Stream file = IsolatedStorageHelper.OpenFile(USER_ACCOUNT_FILE, fileMode.Create))
{
if (null != file)
{
try
{
XDocument xml = new XDocument();
XElement root = new XElement("userAccount");
root.Add(new XAttribute("FirstName", this._firstName));
root.Add(new XAttribute("LastName", this._lastName));
root.Add(new XAttribute("ID", this._id));
root.Add(new XAttribute("Sex", this._sex));
xml.Add(root);
// save xml data
xml.Save(file);
}
catch
{
}
}
}
功能什么Issolated存储
static public IsolatedStorageFileStream OpenFile(string aFilename, FileMode mode)
{
IsolatedStorageFileStream res = null;
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
try
{
res = new IsolatedStorageFileStream(aFilename, mode, FileAccess.ReadWrite, isoStore);
}
catch (Exception exc)
{
if ((null != (exc as IsolatedStorageException)) &&
(FileMode.Open != mode) &&
(true == createPathOnIsolatedStorage(isoStore,aFilename)))
{
try
{
res = new IsolatedStorageFileStream(aFilename, mode, isoStore);
}
catch
{
}
}
}
}
return res;
}
你使用实际的设备还是你正在谈论模拟器? – 2013-02-15 15:02:23
当您的应用程序启动时会发生什么? OpenFile()被调用了吗?您应该用于OpenFile的FileMode应该是FileMode.OpenOrCreate,而不是FileMode.Open。 FileMode.Open将始终重新创建该文件并覆盖您以前拥有的任何数据。 – Gambit 2013-02-15 21:44:52
我在模拟器上测试过。我已经在手机上运行应用程序,一切都变得有效。谢谢 – Nadezhda 2013-02-18 06:57:39