Windows Phone开发中IsolateStorage用法指引

移动开发
Windows Phone开发中IsolateStorage的用法你是否了解,使用IsolateStorage的最大好处就是安全性了,因为只有本程序可以访问该区域,而其他程序是无法访问的。

本文和大家重点学习一下Windows Phone开发中IsolateStorage的用法,在开发时使用silverlight的特色功能IsolateStorage来保存文本文件、XML文件或INI文件的方式来替代了。

Windows Phone开发中IsolateStorage

windowsphone7目前版本上已确定没有文件系统(也就是说filestream、OpenFileDialog这样的功能都是不能使用了)和数据库系统了,那在开发时需要保存一些用户配置信息或临时数据在本地怎么办?答案是只能使用silverlight的特色功能IsolateStorage来保存文本文件、XML文件或INI文件的方式来替代了。

其实使用IsolateStorage的***好处就是安全性了,因为只有本程序可以访问该区域,而其他程序是无法访问的。这样也就可以对一此敏感数据的保存不用自已再加密了。但是这个区域是有限的(默认为2GB),不能够保存很大的数据,以及长期保存数据。如果您非要保存大量数据,以及长期保存的话,目前只能保存在云端而不是本地。

对于Windows Phone开发中IsolateStorage的使用,其实也很简单,和FileStream基本上是一样的。下面就是一些基本操作的代码:

1.打开IsolateStorage:

首先引入命名空间System.IO.IsolatedStorage;

打开storageIsolatedStorageFileisf=IsolatedStorageFile.GetUserStoreForApplication();

2.创建文件夹:

isf.CreateDirectory("MyFolder");

3.创建文件:

StreamWriterwriter=newStreamWriter(newIsolatedStorageFileStream("MyFolder\\myFile.txt",FileMode.OpenOrCreate,isf));

writer.WriteLine(“HelloWorld!”);

writer.Close();

4.读取文件:

StreamReaderreader=newStreamReader(newIsolatedStorageFileStream("MyFolder\\myFile.txt",FileMode.Open,isf));

stringtext=reader.ReadLine();

5.删除文件:

isf.DeleteFile("MyFolder\\myFile.txt");

6.删除文件夹:

isf.DeleteDirectory("MyFolder");

7.判断文件或文件夹是否存在:

isf.FileExit("MyFolder\\myFile.txt");

isf.DirectoryExit("MyFolder");

8.也可以使用Windows Phone开发中IsolateStorageFileStream来操作文件或文件夹,用法和FileStream基本相同.

相关的API详细信息可以查看

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

 

责任编辑:佚名 来源: cnblogs.com
相关推荐

2010-05-11 16:47:32

Windows Pho

2010-06-11 16:01:26

Windows Pho

2012-05-08 13:54:40

ToastPrompt

2010-04-08 17:40:23

Windows Pho

2013-07-30 10:44:31

Windows PhoWindows Pho

2010-05-21 16:24:05

Windows Pho

2010-04-21 17:07:54

Windows Pho

2013-07-30 12:37:56

Windows PhoWindows Pho

2010-06-11 17:01:09

Windows Pho

2010-05-08 16:36:16

Windows Pho

2012-05-25 09:09:25

Windows Pho

2010-06-21 15:39:59

Windows Pho

2013-04-19 16:34:56

Windows PhoWindows Pho

2013-04-16 17:02:50

Windows Pho概论

2013-07-30 11:18:37

Windows PhoWindows Pho

2011-06-07 12:42:15

Windows Pho

2013-04-17 14:00:06

Windows PhoWindows Pho

2010-12-21 10:02:48

SilverlightWindows Pho

2010-11-01 14:49:20

Windows PhoWindows Pho

2010-12-14 18:48:49

微软
点赞
收藏

51CTO技术栈公众号