打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Silverlight之独立存储(10)

  独立存储

  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 = new StreamReader(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();

  本文来自zhaoyu_1979的博客,原文地址:http://blog.csdn.net/zhaoyu_1979/article/details/7467751

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
使用VBA扩展VS.NET集成开发环境,有Flash演示动画
ASP.NET:目录创建和删除
C#文件操作方法大全
Qt工程文件(.pro文件)解读
vb 遍历文件夹 与遍历文件
VB中将file1listbox中的结果批量导出,并且保存为txt文件
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服