The usage of independent storage for Windows Phone development is summarized as follows:
In the past, I had an incorrect understanding. Because small cases have been developed using simulators, data stored independently after the simulators are restarted will be deleted,
It is wrong to think that the real machine may also have such a problem.
Actually, this is not the case. The truth is:
The simulator will be reinitialized every time it is started and will not be saved. But it will be permanently stored on a real mobile phone, just like a hard disk, but it will be lost once the factory settings are restored or the machine is flushed.
In addition, since each WP application allocates a dedicated space, if the application is detached from the mobile phone, data in the isolated storage will also be lost.
Therefore, it is a good choice to store the originally stored data on the WP mobile phone in an independent storage area.
Method 1: isolatedstoragesetting
// Save the data isolatedstorageset=setting = isolatedstorageset=. applicationsettings; string mykey = "myvalue"; string myvalues = ""; if (setting. contains (mykey) {setting [mykey] = mytextbox. text;} else {setting. add (mykey, myvalues);} setting. save (); // read data isolatedstoragesetemedisetting = isolatedstoragesettings. applicationsettings; If (setting. contains ("myvalue") {mytextblock. TEXT = Setting ["myvalue"]. tostring ();} // Delete the data mytextbox. TEXT = ""; isolatedstorageset=iso = isolatedstorageset.pdf. applicationsettings; string mykey = "myvalue"; if (ISO. contains (mykey) {ISO. remove (mykey );}
Method 2: isolatedstoragefile
// Save the data isolatedstoragefile = isolatedstoragefile. getuserstoreforapplication (); string filename = "myfile.txt"; using (var file = new isolatedstoragefilestream (filename, filemode. openorcreate, isolatedstoragefile) {using (VAR writer = new streamwriter (File) {writer. writeline (mytextbox. text) ;}}// read data isolatedstoragefile = isolatedstoragefile. getuserstoreforapplication (); string filename = "myfile.txt"; if (isolatedstoragefile. fileexists (filename) {using (var file = new isolatedstoragefilestream (filename, filemode. open, isolatedstoragefile) {using (VAR reader = new streamreader (File) {mytextblock. TEXT = reader. readline () ;}}// delete data mytextbox. TEXT = ""; isolatedstoragefile = isolatedstoragefile. getuserstoreforapplication (); If (isolatedstoragefile. fileexists ("myfile.txt") {isolatedstoragefile. deletefile ("myfile.txt ");}
You can add the following methods:
Isolatedstorage: weatherinfo temp = NULL; weatherinfo W = NULL; isolatedstoragesetiss ISS = isolatedstorageset.pdf. applicationsettings; If (ISS. trygetvalue ("weatherinfo", out temp) // you can determine whether the value exists {W = temp;}. Code Description: ISS. trygetvalue ("weatherinfo", out temp) returns the boolean type, temp is the output, and "weatherinfo" is the key value.