且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)

更新时间:2022-10-04 19:56:29

[索引页]
[源码下载]


稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)


作者:webabcd


介绍
Silverlight 2.0 数据的独立存储(Isolated Storage):
    IsolatedStorageFile - 操作 独立存储 的类
        IsolatedStorageFile.GetUserStoreForSite() - 按站点获取用户的独立存储
        IsolatedStorageFile.GetUserStoreForApplication() - 按应用程序获取用户的独立存储
    IsolatedStorageSettings - 在独立存储中保存的 key-value 字典表
        IsolatedStorageSettings.SiteSettings - 按站点保存的 key-value 字典表
        IsolatedStorageSettings.ApplicationSettings - 按应用程序保存的 key-value 字典表


在线DEMO
http://webabcd.blog.51cto.com/1787395/342779 


示例
IsolatedStorage.xaml
<UserControl x:Class="Silverlight20.Data.IsolatedStorage" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
        <StackPanel HorizontalAlignment="Left"> 
                <TextBox x:Name="txtMsg" Margin="5" /> 
                <TextBox x:Name="txtMsg2" Margin="5" /> 
                <Button x:Name="increase" Content="增加配额" Click="increase_Click" Margin="5" /> 
        </StackPanel> 
</UserControl>
 
IsolatedStorage.xaml.cs
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)using System; 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)using System.Collections.Generic; 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)using System.Linq; 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)using System.Net; 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)using System.Windows; 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)using System.Windows.Controls; 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)using System.Windows.Documents; 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)using System.Windows.Input; 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)using System.Windows.Media; 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)using System.Windows.Media.Animation; 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)using System.Windows.Shapes; 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)using System.IO.IsolatedStorage; 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)using System.IO; 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)namespace Silverlight20.Data 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)        public partial class IsolatedStorage : UserControl 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)        { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                public IsolatedStorage() 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        InitializeComponent(); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        // 演示 IsolatedStorageFile 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        Demo(); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        // 演示 IsolatedStorageSettings 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        Demo2(); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                /// <summary> 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                /// 演示 IsolatedStorageFile 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                /// </summary> 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                void Demo() 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        // Isolated Storage - 独立存储。一个虚拟文件系统 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        // IsolatedStorageFile - 操作 独立存储 的类 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        //         IsolatedStorageFile.GetUserStoreForSite() - 按站点获取用户的独立存储 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        //         IsolatedStorageFile.GetUserStoreForApplication() - 按应用程序获取用户的独立存储 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                         
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        // using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForSite()) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // DirectoryExists(path) - 指定的路径是否存在 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // CreateDirectory(path) - 创建指定的路径 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // FileExists(path) - 指定的文件是否存在 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // CreateFile(path) - 创建指定的文件 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // GetDirectoryNames() - 获取根目录下的目录名数组 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // GetFileNames()() - 获取根目录下的文件名数组 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // GetDirectoryNames(path) - 获取指定目录下的目录名数组 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // GetFileNames(path) - 获取指定目录下的文件名数组 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // OpenFile() - 打开指定的文件。具体参数参看文档 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // DeleteFile(path) - 删除指定的文件 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // DeleteDirectory(path) - 删除指定的目录(要求目录存在,且目录内无内容) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // Remove() - 关闭 IsolatedStorageFile 对象并移除独立存储内的全部内容 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // 在根目录下创建指定的目录 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                if (!isf.DirectoryExists("Directory01")) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        isf.CreateDirectory("Directory01"); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                if (!isf.DirectoryExists("Directory02")) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        isf.CreateDirectory("Directory02"); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // 创建指定的子目录 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                string subDirectory01 = System.IO.Path.Combine("Directory01""SubDirectory01"); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                string subDirectory02 = System.IO.Path.Combine("Directory01""SubDirectory02"); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                if (!isf.DirectoryExists(subDirectory01)) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        isf.CreateDirectory(subDirectory01); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                if (!isf.DirectoryExists(subDirectory02)) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        isf.CreateDirectory(subDirectory02); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // 根目录下创建指定的文件 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                if (!isf.FileExists("RootFile.txt")) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        IsolatedStorageFileStream isfs = isf.CreateFile("RootFile01.txt"); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        isfs.Close(); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // 在指定的目录下创建指定的文件 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                string file01 = System.IO.Path.Combine(subDirectory01, "File01.txt"); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                string file02 = System.IO.Path.Combine(subDirectory01, "File02.txt"); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                string file03 = System.IO.Path.Combine(subDirectory01, "File03.xml"); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                if (!isf.FileExists(file01)) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        // IsolatedStorageFileStream - 独立存储内的文件流。继承自 FileStream 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        IsolatedStorageFileStream isfs = isf.CreateFile(file01); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        isfs.Close(); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                if (!isf.FileExists(file02)) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        IsolatedStorageFileStream isfs = isf.CreateFile(file02); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        isfs.Close(); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                if (!isf.FileExists(file03)) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        IsolatedStorageFileStream isfs = isf.CreateFile(file03); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        isfs.Close(); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                txtMsg.Text += "根目录下的目录列表:\r\n"
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // 获取根目录下的目录名数组 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                foreach (string directoryName in isf.GetDirectoryNames()) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        txtMsg.Text += directoryName + "\r\n"
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                txtMsg.Text += "根目录下的文件列表:\r\n"
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // 获取根目录下的文件名数组 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                foreach (string fileName in isf.GetFileNames()) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        txtMsg.Text += fileName + "\r\n"
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                txtMsg.Text += "目录 Directory01 下的目录列表:\r\n"
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // 获取 Directory01 目录下的目录名数组 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                foreach (string directoryName in isf.GetDirectoryNames(subDirectory01)) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        txtMsg.Text += directoryName + "\r\n"
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                txtMsg.Text += "目录 Directory01/SubDirectory01 下的*.txt文件列表:\r\n"
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // 获取 Directory01/SubDirectory01 目录下的后缀名为 txt 的文件名数组 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                foreach (string fileName in isf.GetFileNames(System.IO.Path.Combine(subDirectory01, "*.txt"))) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        txtMsg.Text += fileName + "\r\n"
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                if (isf.FileExists(file01)) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        // 在文件 file01 中写入内容 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        IsolatedStorageFileStream streamWrite = isf.OpenFile(file01, FileMode.Open, FileAccess.Write); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        using (StreamWriter sw = new StreamWriter(streamWrite)) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                                sw.WriteLine("我是:webabcd"); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                                sw.WriteLine("我专注于asp.net, Silverlight"); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        txtMsg.Text += "文件 File01.txt 的内容:\r\n"
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        // 读取文件 file01 中的内容 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        IsolatedStorageFileStream streamRead = isf.OpenFile(file01, FileMode.Open, FileAccess.Read); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        using (StreamReader sr = new StreamReader(streamRead)) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                                txtMsg.Text += sr.ReadToEnd(); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // 删除文件 file01 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                if (isf.FileExists(file01)) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        isf.DeleteFile(file01); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                try 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        // 删除目录 subDirectory01 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        isf.DeleteDirectory(subDirectory01); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                catch (IsolatedStorageException ex) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        // IsolatedStorageException - 操作临时存储失败时抛出的异常 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        // 因为 subDirectory01 目录内还有文件,所以会抛异常 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        txtMsg.Text += ex.Message; 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                /// <summary> 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                /// 演示 IsolatedStorageSettings 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                /// </summary> 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                void Demo2() 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        // IsolatedStorageSettings - 在独立存储中保存的 key-value 字典表 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        //         IsolatedStorageSettings.SiteSettings - 按站点保存的 key-value 字典表 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        //         IsolatedStorageSettings.ApplicationSettings - 按应用程序保存的 key-value 字典表 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        IsolatedStorageSettings iss = IsolatedStorageSettings.ApplicationSettings; 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        // Add(key, value) - 添加一对 key-value 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        iss.Add("key""value"); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        txtMsg2.Text += (string)iss["key"] + "\r\n"
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        // 修改指定的 key 的 value 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        iss["key"] = "value2"
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        txtMsg2.Text += (string)iss["key"] + "\r\n"
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        // Remove(key) - 移除指定的 key 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        // Count - 字典表内的总的 key-value 数 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        iss.Remove("key"); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        txtMsg2.Text += iss.Count; 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                private void increase_Click(object sender, RoutedEventArgs e) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        // 演示独立存储的配额的相关操作 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        { 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // Quota - 当前配额(KB) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // IncreaseQuotaTo(newQuotaSize) - 增加到指定的配额 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                // AvailableFreeSpace - 当前的可用配额 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                isf.IncreaseQuotaTo(isf.Quota + 1 * 1024 * 1024); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage) 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                System.Windows.Browser.HtmlPage.Window.Alert( 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                                        string.Format("当前配额:{0};可用配额:{1}", isf.Quota, isf.AvailableFreeSpace)); 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                        } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)                }    
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)        } 
稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)}
 
 
演示 IsolatedStorageFile 的运行结果:
根目录下的目录列表:
Directory01
Directory02
根目录下的文件列表:
RootFile01.txt
__LocalSettings
目录 Directory01 下的目录列表:
SubDirectory01
目录 Directory01/SubDirectory01 下的*.txt文件列表:
File01.txt
File02.txt
文件 File01.txt 的内容:
我是:webabcd
我专注于asp.net, Silverlight
无法删除,目录不为空或不存在。

演示 IsolatedStorageSettings 的运行结果:
value
value2
0


OK
[源码下载]




     本文转自webabcd 51CTO博客,原文链接:http://blog.51cto.com/webabcd/343094,如需转载请自行联系原作者