IsolatedStorageFile 类

定义

表示包含文件和目录的独立存储区域。

public ref class IsolatedStorageFile sealed : IDisposable
public ref class IsolatedStorageFile sealed : System::IO::IsolatedStorage::IsolatedStorage, IDisposable
public sealed class IsolatedStorageFile : IDisposable
public sealed class IsolatedStorageFile : System.IO.IsolatedStorage.IsolatedStorage, IDisposable
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class IsolatedStorageFile : System.IO.IsolatedStorage.IsolatedStorage, IDisposable
type IsolatedStorageFile = class
    interface IDisposable
type IsolatedStorageFile = class
    inherit IsolatedStorage
    interface IDisposable
[<System.Runtime.InteropServices.ComVisible(true)>]
type IsolatedStorageFile = class
    inherit IsolatedStorage
    interface IDisposable
Public NotInheritable Class IsolatedStorageFile
Implements IDisposable
Public NotInheritable Class IsolatedStorageFile
Inherits IsolatedStorage
Implements IDisposable
继承
IsolatedStorageFile
继承
属性
实现

示例

下面的代码示例演示如何在独立存储中创建文件和目录。 首先,检索并放置在变量中的用户、域和程序集隔离的 isoStore 存储区。 CreateDirectory然后调用该方法来创建目录,类的IsolatedStorageFileStream两个实例在这些目录中创建文件。

using System;
using System.IO;
using System.IO.IsolatedStorage;

public class CreatingFilesDirectories
{
    public static void Main()
    {
        using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null))
        {
            isoStore.CreateDirectory("TopLevelDirectory");
            isoStore.CreateDirectory("TopLevelDirectory/SecondLevel");
            isoStore.CreateDirectory("AnotherTopLevelDirectory/InsideDirectory");
            Console.WriteLine("Created directories.");

            isoStore.CreateFile("InTheRoot.txt");
            Console.WriteLine("Created a new file in the root.");

            isoStore.CreateFile("AnotherTopLevelDirectory/InsideDirectory/HereIAm.txt");
            Console.WriteLine("Created a new file in the InsideDirectory.");
        }
    }
}
Imports System.IO
Imports System.IO.IsolatedStorage

Module Module1
    Sub Main()
        Using isoStore As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, Nothing, Nothing)

            isoStore.CreateDirectory("TopLevelDirectory")
            isoStore.CreateDirectory("TopLevelDirectory/SecondLevel")
            isoStore.CreateDirectory("AnotherTopLevelDirectory/InsideDirectory")
            Console.WriteLine("Created directories.")

            isoStore.CreateFile("InTheRoot.txt")
            Console.WriteLine("Created a new file in the root.")

            isoStore.CreateFile("AnotherTopLevelDirectory/InsideDirectory/HereIAm.txt")
            Console.WriteLine("Created a new file in the InsideDirectory.")
        End Using
    End Sub
End Module

注解

此对象对应于特定的独立存储范围,其中存在由 IsolatedStorageFileStream 对象表示的文件。 应用程序可以使用独立存储将数据保存在文件系统自己的独立部分中,而无需在文件系统中指定特定路径。 由于隔离存储的范围限定于特定程序集,因此大多数其他托管代码将无法访问代码的数据(高度受信任的托管代码和管理工具可以从其他程序集访问存储)。 非托管代码可以访问任何独立存储。

有关详细信息,请参阅 独立存储

此类型实现 IDisposable 接口。 使用完类型后,应直接(通过调用其 Dispose 方法)或间接(使用 C# 等 using 语言构造)将其释放。 有关详细信息,请参阅 使用实现 IDisposable 的对象

Important

独立存储不适用于 Windows 8.x 应用商店应用。 请改用 Windows 运行时 API 包含的 Windows.Storage 命名空间中的应用程序数据类来存储本地数据和文件。 有关详细信息,请参阅 Windows 开发人员中心的 应用程序数据

属性

名称 说明
ApplicationIdentity

获取范围隔离存储的应用程序标识。

(继承自 IsolatedStorage)
AssemblyIdentity

获取用于限定隔离存储范围的程序集标识。

(继承自 IsolatedStorage)
AvailableFreeSpace

获取一个值,该值表示可用于独立存储的可用空间量。

CurrentSize
已过时.
已过时.

获取独立存储的当前大小。

DomainIdentity

获取范围隔离存储的域标识。

(继承自 IsolatedStorage)
IsEnabled

获取一个值,该值指示是否启用隔离存储。

MaximumSize
已过时.
已过时.

获取一个值,该值表示在配额建立的限制内可用于独立存储的最大空间量。

Quota

获取一个值,该值表示可用于独立存储的最大空间量。

Scope

获取一个 IsolatedStorageScope 枚举值,该值指定用于隔离存储的范围。

(继承自 IsolatedStorage)
SeparatorExternal

获取可在目录字符串中使用的反斜杠字符。 在派生类中重写时,可能会返回另一个字符。

(继承自 IsolatedStorage)
SeparatorInternal

获取可在目录字符串中使用的句点字符。 在派生类中重写时,可能会返回另一个字符。

(继承自 IsolatedStorage)
UsedSize

获取一个值,该值表示用于隔离存储的空间量。

方法

名称 说明
Close()

关闭以前打开的 GetStore(IsolatedStorageScope, Type, Type)商店, GetUserStoreForAssembly()或者 GetUserStoreForDomain()

CopyFile(String, String, Boolean)

将现有文件复制到新文件,并选择性地覆盖现有文件。

CopyFile(String, String)

将现有文件复制到新文件。

CreateDirectory(String)

在独立存储范围内创建目录。

CreateFile(String)

在独立存储中创建文件。

CreateObjRef(Type)

创建一个对象,其中包含生成用于与远程对象通信的代理所需的所有相关信息。

(继承自 MarshalByRefObject)
DeleteDirectory(String)

删除独立存储范围内的目录。

DeleteFile(String)

删除独立存储范围内的文件。

DirectoryExists(String)

确定指定的路径是否引用独立存储区中的现有目录。

Dispose()

释放该 IsolatedStorageFile命令使用的所有资源。

Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
FileExists(String)

确定指定的路径是否引用独立存储中的现有文件。

Finalize()

允许对象在垃圾回收回收资源之前尝试释放资源并执行其他清理操作。

GetCreationTime(String)

返回指定文件或目录的创建日期和时间。

GetDirectoryNames()

枚举独立存储根目录中的目录。

GetDirectoryNames(String)

枚举与给定搜索模式匹配的独立存储范围中的目录。

GetEnumerator(IsolatedStorageScope)

获取隔离存储范围内存储的枚举器 IsolatedStorageFile

GetFileNames()

枚举独立存储根目录中的文件名。

GetFileNames(String)

获取与搜索模式匹配的文件名。

GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetLastAccessTime(String)

返回上次访问指定文件或目录的日期和时间。

GetLastWriteTime(String)

返回上次写入指定的文件或目录的日期和时间。

GetLifetimeService()
已过时.

检索控制此实例的生存期策略的当前生存期服务对象。

(继承自 MarshalByRefObject)
GetMachineStoreForApplication()

获取与调用代码的应用程序标识对应的计算机范围的独立存储。

GetMachineStoreForAssembly()

获取与调用代码的程序集标识对应的计算机范围的独立存储。

GetMachineStoreForDomain()

获取与应用程序域标识和程序集标识对应的计算机范围的独立存储。

GetPermission(PermissionSet)

由派生类实现时,返回表示从权限集中访问隔离存储的权限。

(继承自 IsolatedStorage)
GetStore(IsolatedStorageScope, Evidence, Type, Evidence, Type)

获取与给定应用程序域和程序集证据对象和类型对应的独立存储。

GetStore(IsolatedStorageScope, Object, Object)

获取与给定应用程序域和程序集证据对象对应的独立存储。

GetStore(IsolatedStorageScope, Object)

获取与给定应用程序标识对应的独立存储。

GetStore(IsolatedStorageScope, Type, Type)

根据应用程序域和程序集证据类型,获取与隔离存储范围对应的独立存储。

GetStore(IsolatedStorageScope, Type)

获取与隔离范围和应用程序标识对象对应的独立存储。

GetType()

获取当前实例的 Type

(继承自 Object)
GetUserStoreForApplication()

获取与调用代码的应用程序标识对应的用户范围的独立存储。

GetUserStoreForAssembly()

获取与调用代码的程序集标识对应的用户范围的独立存储。

GetUserStoreForDomain()

获取与应用程序域标识和程序集标识对应的用户范围的独立存储。

GetUserStoreForSite()

获取用户范围的独立存储,以供虚拟主机域中的应用程序使用。

IncreaseQuotaTo(Int64)

使应用程序能够显式请求更大的配额大小(以字节为单位)。

InitializeLifetimeService()
已过时.

获取生存期服务对象来控制此实例的生存期策略。

(继承自 MarshalByRefObject)
InitStore(IsolatedStorageScope, Type, Type)

初始化新 IsolatedStorage 对象。

(继承自 IsolatedStorage)
InitStore(IsolatedStorageScope, Type)

初始化新 IsolatedStorage 对象。

(继承自 IsolatedStorage)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。

(继承自 MarshalByRefObject)
MoveDirectory(String, String)

将指定目录及其内容移动到新位置。

MoveFile(String, String)

将指定文件移动到新位置,还可以选择指定新的文件名。

OpenFile(String, FileMode, FileAccess, FileShare)

在指定模式下打开一个具有指定读/写访问权限和共享权限的文件。

OpenFile(String, FileMode, FileAccess)

在指定模式下打开具有指定读/写访问权限的文件。

OpenFile(String, FileMode)

在指定模式下打开文件。

Remove()

删除独立存储范围及其所有内容。

Remove(IsolatedStorageScope)

删除所有标识的指定隔离存储范围。

ToString()

返回一个表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅