Learn Windows Phone 7 development together (6. Isolate storage)

Source: Internet
Author: User

In Windows Phone 7, no file system (that is, functions such as filestream and openfiledialog cannot be used) or database system have been determined in the current version, what should I do if I need to save some user configuration information or temporary data locally during development? The answer is that you can only use the special function isolate storage of Silverlight to save text files, XML files, or INI files.

In fact, the biggest benefit of using isolate storage is security, because only this program can access this region, and other programs cannot access it. In this way, you can save this sensitive data without any further encryption. However, this region is limited (2 GB by default). It cannot store large amounts of data or store data for a long time. If you want to save a large amount of data and keep it for a long time, it can only be saved on the cloud instead of local.

The use of isolate storage is actually very simple, basically the same as that of filestream. The following is the code for some basic operations:

1. Enable isolate storage:

First introduce the namespace system. Io. isolatedstorage;

Open storage isolatedstoragefile ISF = isolatedstoragefile. getuserstoreforapplication ();

2. Create a folder:

ISF. createdirectory ("myfolder ");

3. Create a file:

Streamwriter writer = new streamwriter (New isolatedstoragefilestream ("myfolder \ myfile.txt", filemode. openorcreate, ISF ));

Writer. writeline ("Hello World !");

Writer. Close ();

 

4. Read files:

Streamreader reader = new streamreader (New isolatedstoragefilestream ("myfolder \ myfile.txt", filemode. Open, ISF ));

String text = reader. Readline ();

 

5. delete an object:

ISF. deletefile ("myfolder \ myfile.txt ");

6. delete a folder:

ISF. deletedirectory ("myfolder ");

7. check whether a file or folder exists:

ISF. fileexit ("myfolder \ myfile.txt ");

ISF. directoryexit ("myfolder ");

8. You can also use isolatestoragefilestream to operate files or folders. Its usage is basically the same as that of filestream.

For more information about related APIs, see

The http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage (vs.95). aspx

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.