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
继承
属性
实现

示例

下面的代码示例展示了如何在独立存储中创建文件和目录。 首先,检索由用户、域和程序集隔离的存储并将其放置在 变量中 isoStoreCreateDirectory然后调用 方法来创建目录,类的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 接口。 在使用完类型后,您应直接或间接释放类型。 若要直接释放类型,请在 try/catch 块中调用其 Dispose 方法。 若要间接释放类型,请使用 using(在 C# 中)或 Using(在 Visual Basic 中)等语言构造。 有关详细信息,请参阅 IDisposable 接口主题中的“使用实现 IDisposable 的对象”一节。

重要

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

属性

ApplicationIdentity

获取用于确定独立存储范围的应用程序标识。

(继承自 IsolatedStorage)
AssemblyIdentity

获取用于确定独立存储范围的程序集标识。

(继承自 IsolatedStorage)
AvailableFreeSpace

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

AvailableFreeSpace

在派生类中重写时,获取独立存储的可用空间(以字节为单位)。

(继承自 IsolatedStorage)
CurrentSize
已过时.
已过时.

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

DomainIdentity

获取用于确定独立存储范围的域标识。

(继承自 IsolatedStorage)
IsEnabled

获取一个值,该值指示是否启用了独立存储。

MaximumSize
已过时.
已过时.

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

Quota

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

Quota

在派生类中重写时,获取一个值,该值表示可用于独立存储的最大空间量。

(继承自 IsolatedStorage)
Scope

获取指定用于隔离存储区的范围的 IsolatedStorageScope 枚举值。

(继承自 IsolatedStorage)
SeparatorExternal

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

(继承自 IsolatedStorage)
SeparatorInternal

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

(继承自 IsolatedStorage)
UsedSize

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

UsedSize

在派生类中重写时,获取一个值,该值表示用于独立存储的空间量。

(继承自 IsolatedStorage)

方法

Close()

关闭以前用 GetStore(IsolatedStorageScope, Type, Type)GetUserStoreForAssembly()GetUserStoreForDomain() 打开的存储区。

CopyFile(String, String)

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

CopyFile(String, String, Boolean)

将现有文件复制到新文件,还可以覆盖现有文件。

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)

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

GetStore(IsolatedStorageScope, Object, Object)

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

GetStore(IsolatedStorageScope, Type)

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

GetStore(IsolatedStorageScope, Type, Type)

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

GetType()

获取当前实例的 Type

(继承自 Object)
GetUserStoreForApplication()

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

GetUserStoreForAssembly()

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

GetUserStoreForDomain()

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

GetUserStoreForSite()

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

IncreaseQuotaTo(Int64)

使应用程序显式请求一个更大的配额大小,以字节为单位。

IncreaseQuotaTo(Int64)

在派生类中重写时,将提示用户批准独立存储的更大配额大小(以字节为单位)。

(继承自 IsolatedStorage)
InitializeLifetimeService()
已过时.

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

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

初始化新的 IsolatedStorage 对象。

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

初始化新的 IsolatedStorage 对象。

(继承自 IsolatedStorage)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
MemberwiseClone(Boolean)

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

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

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

MoveFile(String, String)

将指定文件移到新位置,还可以允许你指定新文件名。

OpenFile(String, FileMode)

在指定的模式中打开文件。

OpenFile(String, FileMode, FileAccess)

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

OpenFile(String, FileMode, FileAccess, FileShare)

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

Remove()

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

Remove(IsolatedStorageScope)

为所有标识移除指定的独立存储范围。

ToString()

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

(继承自 Object)

适用于

另请参阅