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