Silverlight之独立存储(10)
来源:互联网 发布:公网ip绑定域名 编辑:程序博客网 时间:2024/04/19 10:18
独立存储
代码下载
1. 独立存储
独立存储是一种数据存储机制,它在代码与保存的数据之间定义了标准化的关联方式,从而提供隔离性和安全性。同时,标准化也提供了其他好处。管理员可以使用旨在操作独立存储的工具来配置文件存储空间、设置安全策略及删除未使用的数据。通过独立存储,代码不再需要使用唯一的路径来指定文件系统中的安全位置,同时可以保护数据免遭只具有独立存储访问权限的其他应用程序的损坏。不再需要指示应用程序的存储区域位置的硬编码信息。
2. 代码实现例子关键代码
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
StringBuilder sb = new StringBuilder();
//创建文件夹
store.CreateDirectory("dir1");
stringsub11 = Path.Combine("dir1", "SubDir11");
stringsub12 = Path.Combine("dir1", "SubDir12");
stringsub13 = Path.Combine("dir1", "SubDir13");
store.CreateDirectory(sub11);
store.CreateDirectory(sub12);
store.CreateDirectory(sub13);
store.CreateDirectory("dir2");
store.CreateDirectory("dir2\\sub21");
store.CreateDirectory("dir3");
//创建文件
IsolatedStorageFileStreamf1 = store.CreateFile(Path.Combine(sub11,"InTheRoot1.txt"));
f1.Close();
IsolatedStorageFileStreamf2 = store.CreateFile("InTheRoot12.txt");
f2.Close();
IsolatedStorageFileStreamf3 = store.CreateFile("InTheRoot13.txt");
f3.Close();
//得到文件夹
string[]dirs = store.GetDirectoryNames();
string[]subdirs = store.GetDirectoryNames(Path.Combine("dir1","*"));
//得到文件
string[]files = store.GetFileNames();
stringsearchpath = Path.Combine(sub11, "*.*");
string[]filesInSubDirs = store.GetFileNames(searchpath);
//写文件
strings = "InTheRoot12.txt";
if(store.FileExists(s))
{
try
{
using(StreamWriter sw =newStreamWriter(store.OpenFile(s,FileMode.Open,FileAccess.Write)))
{
sw.WriteLine("滚滚长江东逝水!");
}
}
catch(IsolatedStorageException ex)
{
}
}
//读文件
try
{
using(StreamReader reader =newStreamReader(store.OpenFile(s,FileMode.Open,FileAccess.Read)))
{
stringcontents = reader.ReadToEnd();
sb.AppendLine(s + "内容:");
sb.AppendLine(contents);
}
}
catch(IsolatedStorageException ex)
{
sb.AppendLine(ex.Message);
}
//删除文件,删除文件夹
store.DeleteFile(Path.Combine(sub11,"InTheRoot1.txt"));
store.DeleteDirectory(sub11);
//store.Remove();
代码下载
- Silverlight之独立存储(10)
- Silverlight独立存储之读写文本文件
- Silverlight独立存储之读写文件
- silverlight 独立存储
- 稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)
- Silverlight Isolated Storage 独立存储
- Silverlight Isolated Storage 独立存储
- 解读Silverlight中独立存储
- Silverlight 独立存储配置
- 详解Silverlight 2中的独立存储
- 详解Silverlight 2中的独立存储(转载)
- 详解Silverlight 2中的独立存储
- html5学习笔记之七(独立数据存储)
- Windows Phone 独立存储之IsolatedStorageFile
- Windows Phone开发之独立存储二
- Windows Phone 独立存储之IsolatedStorageSettings
- 独立存储
- 独立存储
- mysql复合索引优化
- 使用eclipse更新ADT速度很慢的解决方法
- windows下svn服务器配置
- 修改 mysql 表类型
- poj 1087 我们一起学习网络流吧
- Silverlight之独立存储(10)
- c++排序函数详解
- [网络相关]/etc/host.conf & /etc/hosts/ & /etc/resolv.conf等等
- 四月雨
- vmware:Cannot open the disk 'XXX' or one of the snapshot disks it depends on. reason: failed to lock
- 模板函数2
- Mysql回滚不成功
- BoundsChecker使用
- c++中qsort()排序函数的使用qsort函数应用大全