Silverlight 3.0 Isolated Storage 独立存储空间
????? Silverlight支持一種類似Cookie的獨立存儲,它是基于客戶端的文件系統,每個Silverlight應用程序都被分配了自己的獨立的存儲空間.
???? 這個存儲空間在不同的操作系統下是不同的WindowsXP下 是根據賬戶來分配的.一般在
C:\Document and Setting\Administrator\Local Setting\Application data\Microsoft\Silverlight\is\
??? 我的是操作系統是win7企業版,位置在
C:\Users\Administrator\AppData\LocalLow\Microsoft\Silverlight\is\
? 了解了 Isolated Storge是干嘛的
?? 接下來來介紹下 怎么在程序中應用這個存儲空間來操作目錄和文件.
1,Isolated Storge 根據應用程序不同, 有應用程序和站點兩種類型,
? 應用程序:IsolatedStorageFile.GetUserStoreForApplication();
? 站點:IsolatedStorageFile.GetUserStoreForSite();
在操作Isolated Storge? 要引入using System.IO.IsolatedStorage;命名空間
2,下面就是一寫代碼了.大家可以復制下來看看.Go
//創建目錄
?????? public void CreateDir(string dirName)
?????? {
?????????? IsolatedStorageFile stoedFile = IsolatedStorageFile.GetUserStoreForApplication();
?????????? stoedFile.CreateDirectory(dirName);
?????? }
?????? //列目錄
?????? public void LoadDirs()
?????? {
?????????? using (IsolatedStorageFile storeFile = IsolatedStorageFile.GetUserStoreForApplication())
?????????? {
?????????????? var itemSource = storeFile.GetDirectoryNames("*");
?????????? }
?????? }
?????? //刪除目錄
?????? public void DeleteDir(string dirPath)
?????? {
?????????? using (IsolatedStorageFile stro = IsolatedStorageFile.GetUserStoreForApplication())
?????????? {
?????????????? stro.DeleteDirectory(dirPath);
?????????? }
?????? }
?????? //創建文件
?????? public void SaveFile(string savePath,string content)
?????? {
?????????? IsolatedStorageFile storeFile = IsolatedStorageFile.GetUserStoreForApplication();
?????????? IsolatedStorageFileStream sf = storeFile.CreateFile(savePath);
?????????? using (StreamWriter sw = new StreamWriter(sf))
?????????? {
?????????????? sw.WriteLine(content);
?????????? }
?????????? sf.Close();
?????? }
?????? //讀取文件
?????? public void LoadFile(string readPath)
?????? {
?????????? string content = string.Empty;
?????????? using (IsolatedStorageFile storeFile = IsolatedStorageFile.GetUserStoreForApplication())
?????????? {
?????????????? if (storeFile.FileExists(readPath))
?????????????? {
?????????????????? StreamReader sr = new StreamReader(storeFile.OpenFile(readPath,FileMode.Open,FileAccess.Read));
?????????????????? content = sr.ReadToEnd();
?????????????? }
?????????? }
?????? }
?????? //刪除文件
?????? public void DeleteFile(string path)
?????? {
?????????? using (IsolatedStorageFile storeFile = IsolatedStorageFile.GetUserStoreForApplication())
?????????? {
?????????????? storeFile.DeleteFile(path);
?????????? }
?????? }
我做了一個實例的Demo喜歡的喜歡的朋友可以下載來看看
下載地址
又一天的陽光灑滿大地...
轉載于:https://www.cnblogs.com/xiaogangqq123/archive/2010/05/19/1739151.html
總結
以上是生活随笔為你收集整理的Silverlight 3.0 Isolated Storage 独立存储空间的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 高等数学(第七版)同济大学 习题2-4
- 下一篇: 计算机网络第七版笔记--第二章