Windows phone7 isolated storage space

Source: Internet
Author: User

Isolate buckets:

    • Directory operations
    • File Operations
    • ApplicationProgramConfiguration Information

Concept of isolated Bucket: All file I/O operations are restricted in the isolated bucket. In the isolated bucket, you can add, delete, and modify directories and files, and store program configuration information in the isolated bucket.

Important classes:

    • Isolatedstoragefile is used to isolate directories and files in a bucket,
    • Isolatedstoragefilestream is used for read/write operations to isolate streams in a bucket.
    • Isolatedstoragefilesettings is a dictionary used to store program configuration information.

Quota Management:

    • There is no limit on the quota of isolated buckets in Windows Phone.
Using system; using system. collections. generic; using system. LINQ; using system. net; using system. windows; using system. windows. controls; using system. windows. documents; using system. windows. input; using system. windows. media; using system. windows. media. animation; using system. windows. shapes; using Microsoft. phone. controls; using system. io. isolatedstorage; using system. io; namespace isolatedstorage {public partial class mainpage: phoneapplicationpage {// constructor public mainpage () {initializecomponent ();} private const string Foldername = "temp1 "; private const string filename = Foldername + "/address.txt"; private const string settingname = "sname "; /// <summary> /// create a folder /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> private void button#click (Object sender, routedeventargs e) {using (isolatedstoragefile file = isolatedstoragefile. getuserstoreforapplication () {file. createdirectory (Foldername );}} /// <summary> /// check whether the folder exists /// </Summary> /// <Param name = "sender"> </param> // <Param name = "E"> </param> private void button2_click (Object sender, routedeventargs e) {using (isolatedstoragefile file = isolatedstoragefile. getuserstoreforapplication () {If (file. directoryexists (Foldername) {MessageBox. show ("already exists");} else {MessageBox. show ("nonexistent ");}}} /// <summary> /// Delete the directory /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> private void button3_click (Object sender, routedeventargs e) {using (isolatedstoragefile file = isolatedstoragefile. getuserstoreforapplication () {file. deletedirectory (Foldername );}} /// <summary> /// create a file /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> private void button4_click (Object sender, routedeventargs e) {using (isolatedstoragefile file = isolatedstoragefile. getuserstoreforapplication () {isolatedstoragefilestream = file. createfile (filename); stream. close ();}} /// <summary> /// check whether the file exists /// </Summary> /// <Param name = "sender"> </param> // <Param name = "E"> </param> private void button5_click (Object sender, routedeventargs e) {using (isolatedstoragefile file = isolatedstoragefile. getuserstoreforapplication () {If (file. fileexists (filename) {MessageBox. show ("already exists" + filename);} else {MessageBox. show ("nonexistent ");}}} /// <summary> /// delete a file /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> private void button6_click (Object sender, routedeventargs e) {using (isolatedstoragefile file = isolatedstoragefile. getuserstoreforapplication () {file. deletefile (filename );}} /// <summary> /// add content to the file /// </Summary> /// <Param name = "sender"> </param> // <param name = "E"> </param> private void button7_click (Object sender, routedeventargs e) {using (isolatedstoragefile file = isolatedstoragefile. getuserstoreforapplication () {using (isolatedstoragefilestream stream = file. openfile (filename, filemode. openorcreate, fileaccess. readwrite) {streamwriter writer = new streamwriter (Stream); writer. writeline (textbox1.text); writer. close (); textbox1.text = "";}}} /// <summary> /// read the file content /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> private void button8_click (Object sender, routedeventargs e) {using (isolatedstoragefile file = isolatedstoragefile. getuserstoreforapplication () {using (isolatedstoragefilestream stream = file. openfile (filename, filemode. openorcreate, fileaccess. readwrite) {using (streamreader reader = new streamreader (Stream) {textbox1.text = reader. readtoend ();}}}} /// <summary> /// Save the program configuration information /// </Summary> /// <Param name = "sender"> </param> // <Param name = "E"> </param> private void button9_click (Object sender, routedeventargs e) {isolatedstoragesettings. applicationsettings [settingname] = textbox2.text; isolatedstorageset.pdf. applicationsettings. save (); textbox2.text = "";} /// <summary> /// read the program configuration information /// </Summary> /// <Param name = "sender"> </param> // <Param name = "E"> </param> private void button10_click (Object sender, routedeventargs e) {If (isolatedstoragesettings. applicationsettings. contains (settingname) {textbox2.text = isolatedstoragesettings. applicationsettings [settingname]. tostring ();}}}}

 

 

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.