silverlight   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

[索引页] [源码下载] 稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated StoragE) 作者: webabcd 介绍 Silverlight 2.0 数据的独立存储(Isolated StoragE):     IsolatedStorageFile - 操作 独立存储 的类         IsolatedStorageFile.GetUserStoreF
@H_450_7@
[索引页]
[源码下载]


稳扎稳打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://www.voidcn.com/article/p-ounmxjds-tq.html  


示例
IsolatedStorage.xaml
<UserControl x:Class="Silverlight20.Data.IsolatedStorage"
        xmlns="http://scheR_324_11845@as.microsoft.com/winfx/2006/xaml/presentation"    
        xmlns:x="http://scheR_324_11845@as.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,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
[源码下载]

大佬总结

以上是大佬教程为你收集整理的稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)全部内容,希望文章能够帮你解决稳扎稳打Silverlight(16) - 2.0数据之独立存储(Isolated Storage)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。