Two usage methods of independent storage for Windows Phone development

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.