首页  ·  知识 ·  移动开发
windowphone独立存储空间System.IO.IsolatedStorage
音乐啤酒    Wphone  编辑:dezai   图片来源:网络
window phone中的程序不能随便读取和存储手机中数据,window phone定义了一个专门的机制为每个程序指定特殊的区域来存储读取数据。叫做独立存储. 在window pho
window phone 独立存储空间System.IO.IsolatedStorage
 
window phone中的程序不能随便读取和存储手机中数据,window phone定义了一个专门的机制为每个程序指定特殊的区域来存储读取数据。叫做独立存储
 
在window phong中System.io下只有IsolatedStorage这个命名空间。
 
 
 
独立存储空间
 
独立存储空间是一个虚拟的文件系统,每个应用程序只能访问自己的存储空间,不能访问其他的。
 
独立存储空间又1个或多个独立文件组成,也有文件夹系统。
 
主要用的方法有两个
 
1.key/value模式的配置类          
 
System.IO.IsolatedStorage.IsolatedStorageSettings setting = IsolatedStorageSettings.ApplicationSettings;
 
 setting.Add();
            setting.Contains();
            setting.Remove();
            setting.TryGetValue();
            setting["key"] = “Value”;
 
 
 
 默认情况下IsolatedStorageSettings在应用程序关闭的时候才会写入独立存储空间中,为了防止应用程序意外中断可以使用Save()方法强制写入独立存储空间

2.存储和读取文件模式
 
IsolatedStorageFile这个类可以用来保存和读取文件, IsolatedStorageFileStream 这个用来读取和写入文件
 
using(System.IO.IsolatedStorage.IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
 
{}
 
IsolatedStorageFile.GetUserStoreForApplication()这个方法得到该应用程序对应的用户独立存储空间。
 
一段代码示例
 
 
?
 
 
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
WriteableBitmap bmImage = new WriteableBitmap(image);
if (!store.DirectoryExists("Images"))
{
store.CreateDirectory("Images");
}
using (IsolatedStorageFileStream isoStream =
store.OpenFile(@"Images\userPhoto.jpg", FileMode.OpenOrCreate))
{
Extensions.SaveJpeg(
bmImage,
isoStream,
bmImage.PixelWidth,
bmImage.PixelHeight,
0,
100);
}
}

 
 

 
本文作者:音乐啤酒 来源:网络
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读