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
[索引页]
[源码下载]


稳扎稳打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.cnblogs.com/webabcd/archive/2008/10/09/1307486.html


示例
IsolatedStorage.xaml

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

< UserControl  x:Class ="Silverlight20.Data.IsolatedStorage"

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

    xmlns
="http://scheR_128_11845@as.microsoft.com/winfx/2006/xaml/presentation"  

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

    xmlns:x
="http://scheR_128_11845@as.microsoft.com/winfx/2006/xaml" >

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

    
< StackPanel  HorizontalAlignment ="Left" >

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

        
< TextBox  x:Name ="txtmsg"  Margin ="5"   />

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

        
< TextBox  x:Name ="txtmsg2"  Margin ="5"   />

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

        
< Button  x:Name ="increase"  Content ="增加配额"  Click ="increase_Click"  Margin ="5"   />

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

    
</ StackPanel >

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

</ UserControl >

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


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)

            
@H_507_489@//
@H_507_489@ 演示 IsolatedStorageFile
@H_507_489@

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

            Demo();

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


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

            
@H_507_489@//@H_507_489@ 演示 IsolatedStorageSetTings@H_507_489@

稳扎稳打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)

        
///@H_507_489<sumMary>@H_507_489@

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

        ///@H_507_489@ 演示 IsolatedStorageFile

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

        ///@H_507_489</sumMary>

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

        void Demo()

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

        
{

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

            
@H_507_489@//
@H_507_489@ Isolated Storage - 独立存储。一个虚拟文件系统

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


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

            @H_507_489@//@H_507_489@ IsolatedStorageFile - 操作 独立存储 的类

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

            @H_507_489@//@H_507_489@     IsolatedStorageFile.GetUserStoreForSite() - 按站点获取用户的独立存储

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

            @H_507_489@//@H_507_489@     IsolatedStorageFile.GetUserStoreForApplication() - 按应用程序获取用户的独立存储

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

            

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

            @H_507_489@//@H_507_489@ using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForSite())@H_507_489@

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

            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())

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

            
{

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

                
@H_507_489@//
@H_507_489@ directoryExists(path) - 指定的路径是否存在

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

                @H_507_489@//@H_507_489@ CreateDirectory(path) - 创建指定的路径

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

                @H_507_489@//@H_507_489@ FileExists(path) - 指定的文件是否存在

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

                @H_507_489@//@H_507_489@ CreateFile(path) - 创建指定的文件

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

                @H_507_489@//@H_507_489@ GetDirectoryNames() - 获取根目录下的目录名数组

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

                @H_507_489@//@H_507_489@ GetFilenames()() - 获取根目录下的文件名数组

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

                @H_507_489@//@H_507_489@ GetDirectoryNames(path) - 获取指定目录下的目录名数组

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

                @H_507_489@//@H_507_489@ GetFilenames(path) - 获取指定目录下的文件名数组

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

                @H_507_489@//@H_507_489@ OpenFile() - 打开指定的文件。具体参数参看文档

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

                @H_507_489@//@H_507_489deleteFile(path) - 删除指定的文件

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

                @H_507_489@//@H_507_489deleteDirectory(path) - 删除指定的目录(要求目录存在,且目录内无内容

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

                @H_507_489@//@H_507_489@ remove() - @L_801_50@ IsolatedStorageFile 对象并移除独立存储内的全部内容

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


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


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

                @H_507_489@//@H_507_489@ 在根目录下创建指定的目录@H_507_489@

稳扎稳打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)

                
@H_507_489@//@H_507_489@ 创建指定的子目录@H_507_489@

稳扎稳打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)

                
@H_507_489@//@H_507_489@ 根目录下创建指定的文件@H_507_489@

稳扎稳打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)

                
@H_507_489@//@H_507_489@ 在指定的目录下创建指定的文件@H_507_489@

稳扎稳打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)

                    
@H_507_489@//
@H_507_489@ IsolatedStorageFileStream - 独立存储内的文件流。继承自 FileStream@H_507_489@

稳扎稳打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)

                
@H_507_489@//@H_507_489获取根目录下的目录名数组@H_507_489@

稳扎稳打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)

                
@H_507_489@//@H_507_489获取根目录下的文件名数组@H_507_489@

稳扎稳打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)

                
@H_507_489@//@H_507_489获取 directory01 目录下的目录名数组@H_507_489@

稳扎稳打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)

                
@H_507_489@//@H_507_489获取 directory01/subdirectory01 目录下的后缀名为 txt 的文件名数组@H_507_489@

稳扎稳打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)

                    
@H_507_489@//
@H_507_489@ 在文件 file01 中写入内容@H_507_489@

稳扎稳打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))

@H_658_1976@

                    
{

稳扎稳打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)

                    
@H_507_489@//@H_507_489@ 读取文件 file01 中的内容@H_507_489@

稳扎稳打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)

                
@H_507_489@//@H_507_489删除文件 file01@H_507_489@

稳扎稳打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)

                    
@H_507_489@//
@H_507_489删除目录 subdirectory01@H_507_489@

稳扎稳打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)

                    
@H_507_489@//
@H_507_489@ IsolatedStorageException - 操作临时存储失败时抛出的异常

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


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

                    @H_507_489@//@H_507_489@ 因为 subdirectory01 目录内还有文件,所以会抛异常@H_507_489@

稳扎稳打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)

        
///@H_507_489<sumMary>@H_507_489@

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

        ///@H_507_489@ 演示 IsolatedStorageSetTings

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

        ///@H_507_489</sumMary>

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

        void Demo2()

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

        
{

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

            
@H_507_489@//
@H_507_489@ IsolatedStorageSetTings - 在独立存储中保存的 key-value 字典表

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

            @H_507_489@//@H_507_489@     IsolatedStorageSetTings.SiteSetTings - 按站点保存的 key-value 字典表

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

            @H_507_489@//@H_507_489@     IsolatedStorageSetTings.ApplicationSetTings - 按应用程序保存的 key-value 字典表@H_507_489@

稳扎稳打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)

            
@H_507_489@//@H_507_489@ Add(key, value) - 添加一对 key-value@H_507_489@

稳扎稳打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)

            
@H_507_489@//@H_507_489修改指定的 key 的 value@H_507_489@

稳扎稳打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)

            
@H_507_489@//@H_507_489@ remove(key) - 移除指定的 key

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

            @H_507_489@//@H_507_489@ Count - 字典表内的总的 key-value 数@H_507_489@

稳扎稳打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)

            
@H_507_489@//
@H_507_489@ 演示独立存储的配额的相关操作@H_507_489@

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

            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())

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

            
@H_419_2294@

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

{

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

                
@H_507_489@//
@H_507_489@ Quota - 当前配额(KB)

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

                @H_507_489@//@H_507_489@ IncreaseQuotaTo(newQuotaSizE) - 增加到指定的配额

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

                @H_507_489@//@H_507_489@ AvailableFreeSpace - 当前的可用配额@H_507_489@

稳扎稳打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)

}

稳扎稳打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,请注明来意。