Saturday, 15 February 2014

c# - WP7 Saving data in isolated storage -



c# - WP7 Saving data in isolated storage -

i save info in isolated storage, when restart phone can not read info there. isolated storage empty. why?

if don't switch off phone work ok

this code:

using (stream file = isolatedstoragehelper.openfile(user_account_file, filemode.create)) { if (null != file) { seek { 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 info xml.save(file); } grab { } } }

function create file in issolated storage

static public isolatedstoragefilestream openfile(string afilename, filemode mode) { isolatedstoragefilestream res = null; using (isolatedstoragefile isostore = isolatedstoragefile.getuserstoreforapplication()) { seek { res = new isolatedstoragefilestream(afilename, mode, fileaccess.readwrite, isostore); } grab (exception exc) { if ((null != (exc isolatedstorageexception)) && (filemode.open != mode) && (true == createpathonisolatedstorage(isostore,afilename)) ) { seek { res = new isolatedstoragefilestream(afilename, mode, isostore); } grab { } } } } homecoming res; }

if talking running on emulator, normal behavior. emulator not preserve isolated storage default.

a physical device maintain info in storage unless explicitly reset, application uninstalled or content deleted user through 1 of means provided application.

c# windows-phone-7

No comments:

Post a Comment