[Windows Phone 7] Storage

Source: Internet
Author: User

Currently, data stored in windwos Phone 7 must be written to an independent storage space. There are two storage methods: 1. Independent file storage; 2. Independent storage.

(1) Independent file storage

The usage of independent file storage is similar to that of files.

Write:

// Obtain the virtual store for applicationisolatedstoragefile mystore = isolatedstoragefile. getuserstoreforapplication (); // create a new folder and call it "imagefolder" mystore. createdirectory ("imagefolder"); // create a new file and assign a streamwriter to the store and this new file (myfile.txt) // also take the text contents from the txtwrite control and write it to myfile.txt streamwriter writefile = new streamwriter (New isolatedstoragefilestream ("imagefolder \ myfile.txt", filemode. openorcreate, mystore); writefile. writeline (txtwrite. text); writefile. close ();

Read:

 
// Obtain a virtual store for application isolatedstoragefile mystore = isolatedstoragefile. getuserstoreforapplication (); // this code will open and read the contents of myfile.txt // Add exception in case the user attempts to click "read button first. streamreader readfile = NULL; try {readfile = new streamreader (New isolatedstoragefilestream ("imagefolder \ myfile.txt", filemode. open, mystore); string filetext = readfile. readline (); // The control txtread will display the text entered in the file txtread. TEXT = filetext; readfile. close ();} catch {txtread. TEXT = "need to create directory and the file first. ";}

(2) Set storage independently

// Obtain the storage object isolatedstoragesettings settings = isolatedstoragesettings. applicationsettings; // write data setting ["name"] = "bill"; setting ["Age"] = "20; setting. save (); // read data string name = Setting ["name"];

For more specific examples, refer to the example of Microsoft settingssample, which provides detailed instructions on how to configure storage independently.

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.