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