Learn Windows Phone 7 development (six isolate Storage)

Source: Internet
Author: User
Tags file system

Windows Phone 7 has been identified on the current version of no file system (that is, FileStream, OpenFileDialog, such as features are not available) and the database system, which need to save some user configuration information or temporary data in the development of local how to do? The answer is instead of using Silverlight's feature isolate storage 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 the zone, and other programs are inaccessible. This allows you to save a sensitive data without encrypting it yourself. But this area is limited (by default 2GB), it is not able to save large data and save data for a long time. If you have to keep a large amount of data and save it for a long time, you can only save it in the cloud instead of the local.

The use of isolate storage is actually very simple, and FileStream is basically the same. The following are some basic operations code:

1. Open Isolate Storage:

Firstly, the namespace System.IO.IsolatedStorage is introduced.

Open storage IsolatedStorageFile ISF = Isolatedstoragefile.getuserstoreforapplication ();

2. To create a folder:

Isf. CreateDirectory ("MyFolder");

3. To create a file:

StreamWriter writer = new StreamWriter(new IsolatedStorageFileStream("MyFolder\\myFile.txt", FileMode.OpenOrCreate, isf));
writer.WriteLine(“Hello World!”);
writer.Close();

4. Read file:

StreamReader reader = new StreamReader(new IsolatedStorageFileStream("MyFolder\\myFile.txt", FileMode.Open, isf));
string text = reader.ReadLine();

5. To delete a file:

Isf. DeleteFile ("Myfolder\\myfile.txt");

6. To delete a folder:

Isf. DeleteDirectory ("MyFolder");

7. To determine whether a file or folder exists:

Isf. FileExit ("Myfolder\\myfile.txt");

Isf. Directoryexit ("MyFolder");

8. You can also use Isolatestoragefilestream to manipulate files or folders, which are basically the same as FileStream.

The relevant API details can be viewed

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.