[英]WP7 Saving data in isolated storage
我將數據保存在獨立存儲中,但是當我重新啟動手機時,我無法從那里讀取這些數據。 隔離存儲是空的。 為什么?
如果我不關掉手機所有的工作好吧
這是我的代碼:
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 Storage中創建文件的功能
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;
}
如果您正在討論在模擬器上運行此操作,這是正常行為 。 默認情況下,模擬器不會保留隔離存儲。
除非顯式重置,應用程序已卸載或用戶通過應用程序提供的方法之一刪除了內容,否則物理設備將始終將數據保留在存儲中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.