IsolatedStorageFile 类

定义

表示包含文件和目录的独立存储区。Represents an isolated storage area containing files and directories.

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

示例

下面的代码示例展示了如何在独立存储中创建文件和目录。The following code example illustrates how to create files and directories in an isolated store. 首先,将检索一个按用户、域和程序集隔离的存储区,并将其放置在 isoStore 的变量中。First, a store that is isolated by user, domain, and assembly is retrieved and placed in the isoStore variable. 然后调用 CreateDirectory 方法来创建目录,IsolatedStorageFileStream 类的两个实例在这些目录中创建文件。The CreateDirectory method is then called to create directories, and two instances of the IsolatedStorageFileStream class create files in these directories.

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 对象表示。This object corresponds to a specific isolated storage scope, where files represented by IsolatedStorageFileStream objects exist. 应用程序可以使用独立存储将数据保存在文件系统自身的隔离部分中,而无需在文件系统中指定特定路径。Applications can use isolated storage to save data in their own isolated portion of the file system, without having to specify a particular path within the file system. 由于独立存储区的作用域为特定程序集,因此,大多数其他托管代码将无法访问您的代码的数据(高度信任的托管代码和管理工具可以访问其他程序集中的存储)。Since isolated stores are scoped to particular assemblies, most other managed code will not be able to access your code's data (highly trusted managed code and administration tools can access stores from other assemblies). 非托管代码可以访问任何独立的存储区。Unmanaged code can access any isolated stores.

有关详细信息,请参阅 独立存储For more information, see Isolated Storage.

此类型实现 IDisposable 接口。This type implements the IDisposable interface. 在使用完类型后,您应直接或间接释放类型。When you have finished using the type, you should dispose of it either directly or indirectly. 若要直接释放类型,请在 Disposetry/ 块中调用其 catch 方法。To dispose of the type directly, call its Dispose method in a try/catch block. 若要间接释放类型,请使用 using(在 C# 中)或 Using(在 Visual Basic 中)等语言构造。To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). 有关详细信息,请参阅 IDisposable 接口主题中的“使用实现 IDisposable 的对象”一节。For more information, see the "Using an Object that Implements IDisposable" section in the IDisposable interface topic.

重要

独立存储不适用于 Windows 8.x 应用商店Windows 8.x Store 应用。Isolated storage is not available for Windows 8.x 应用商店Windows 8.x Store apps. 相反,使用 Windows.Storage API 中包含的 Windows 运行时Windows Runtime 命名空间中的应用程序数据类来存储本地数据和文件。Instead, use the application data classes in the Windows.Storage namespaces included in the Windows 运行时Windows Runtime API to store local data and files. 有关详细信息,请参阅 Windows 开发人员中心的 应用程序数据For more information, see Application data in the Windows Dev Center.

属性

ApplicationIdentity

获取用于确定独立存储范围的应用程序标识。Gets an application identity that scopes isolated storage.

(继承自 IsolatedStorage)
AssemblyIdentity

获取用于确定独立存储范围的程序集标识。Gets an assembly identity used to scope isolated storage.

(继承自 IsolatedStorage)
AvailableFreeSpace

获取一个值,该值表示独立存储的可用空间量。Gets a value that represents the amount of free space available for isolated storage.

CurrentSize

获取独立存储的当前大小。Gets the current size of the isolated storage.

DomainIdentity

获取用于确定独立存储范围的域标识。Gets a domain identity that scopes isolated storage.

(继承自 IsolatedStorage)
IsEnabled

获取一个值,该值指示是否启用了独立存储。Gets a value that indicates whether isolated storage is enabled.

MaximumSize

获取一个值,该值表示在由配额设定的限制内独立存储的最大可用空间。Gets a value representing the maximum amount of space available for isolated storage within the limits established by the quota.

Quota

获取一个值,该值表示独立存储的最大可用空间量。Gets a value that represents the maximum amount of space available for isolated storage.

Scope

获取指定用于隔离存储区的范围的 IsolatedStorageScope 枚举值。Gets an IsolatedStorageScope enumeration value specifying the scope used to isolate the store.

(继承自 IsolatedStorage)
SeparatorExternal

获取可在目录字符串中使用的反斜杠字符。Gets a backslash character that can be used in a directory string. 当在派生类中重写后,可能会返回另一个字符。When overridden in a derived class, another character might be returned.

(继承自 IsolatedStorage)
SeparatorInternal

获取可在目录字符串中使用的句点字符。Gets a period character that can be used in a directory string. 当在派生类中重写后,可能会返回另一个字符。When overridden in a derived class, another character might be returned.

(继承自 IsolatedStorage)
UsedSize

获取一个值,该值表示用于独立存储的空间量。Gets a value that represents the amount of the space used for isolated storage.

方法

Close()

关闭以前用 GetStore(IsolatedStorageScope, Type, Type)GetUserStoreForAssembly()GetUserStoreForDomain() 打开的存储区。Closes a store previously opened with GetStore(IsolatedStorageScope, Type, Type), GetUserStoreForAssembly(), or GetUserStoreForDomain().

CopyFile(String, String)

将现有文件复制到新文件。Copies an existing file to a new file.

CopyFile(String, String, Boolean)

将现有文件复制到新文件,还可以覆盖现有文件。Copies an existing file to a new file, and optionally overwrites an existing file.

CreateDirectory(String)

在独立存储范围中创建目录。Creates a directory in the isolated storage scope.

CreateFile(String)

在独立存储区中创建文件。Creates a file in the isolated store.

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
DeleteDirectory(String)

删除独立存储范围中的目录。Deletes a directory in the isolated storage scope.

DeleteFile(String)

删除独立存储范围中的文件。Deletes a file in the isolated storage scope.

DirectoryExists(String)

确定指定的路径是否指的是独立存储区中的现有目录。Determines whether the specified path refers to an existing directory in the isolated store.

Dispose()

释放 IsolatedStorageFile 使用的所有资源。Releases all resources used by the IsolatedStorageFile.

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
FileExists(String)

确定指定的路径是否指的是独立存储区中的现有文件。Determines whether the specified path refers to an existing file in the isolated store.

Finalize()

在垃圾回收将某一对象回收前允许该对象尝试释放资源并执行其他清理操作。Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.

GetCreationTime(String)

返回指定文件或目录的创建日期和时间。Returns the creation date and time of a specified file or directory.

GetDirectoryNames()

枚举独立存储根处的目录。Enumerates the directories at the root of an isolated store.

GetDirectoryNames(String)

枚举独立存储范围中与给定搜索模式匹配的目录。Enumerates the directories in an isolated storage scope that match a given search pattern.

GetEnumerator(IsolatedStorageScope)

获取独立存储范围中 IsolatedStorageFile 存储区的枚举器。Gets the enumerator for the IsolatedStorageFile stores within an isolated storage scope.

GetFileNames()

枚举独立存储根处的文件名。Enumerates the file names at the root of an isolated store.

GetFileNames(String)

获取与搜索模式匹配的文件名。Gets the file names that match a search pattern.

GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetLastAccessTime(String)

返回上次访问指定文件或目录的日期和时间。Returns the date and time a specified file or directory was last accessed.

GetLastWriteTime(String)

返回上次写入指定文件或目录的日期和时间。Returns the date and time a specified file or directory was last written to.

GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetMachineStoreForApplication()

获取与调用代码的应用程序标识对应的计算机范围的独立存储。Obtains machine-scoped isolated storage corresponding to the calling code's application identity.

GetMachineStoreForAssembly()

获取与调用代码的程序集标识对应的计算机范围的独立存储。Obtains machine-scoped isolated storage corresponding to the calling code's assembly identity.

GetMachineStoreForDomain()

获取与应用程序域标识和程序集标识对应的计算机范围的独立存储。Obtains machine-scoped isolated storage corresponding to the application domain identity and the assembly identity.

GetPermission(PermissionSet)

当由派生类实现时,从权限集中返回表示对独立存储的访问权限的权限。When implemented by a derived class, returns a permission that represents access to isolated storage from within a permission set.

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

获取与给定应用程序域和程序集证据对象及类型对应的独立存储。Obtains isolated storage corresponding to the given application domain and the assembly evidence objects and types.

GetStore(IsolatedStorageScope, Object)

获取与给定应用程序标识对应的独立存储。Obtains isolated storage corresponding to the given application identity.

GetStore(IsolatedStorageScope, Object, Object)

获取与给定的应用程序域和程序集证据对象相对应的独立存储。Obtains the isolated storage corresponding to the given application domain and assembly evidence objects.

GetStore(IsolatedStorageScope, Type)

获取与隔离范围和应用程序标识对象对应的独立存储。Obtains isolated storage corresponding to the isolation scope and the application identity object.

GetStore(IsolatedStorageScope, Type, Type)

已知应用程序域和程序集证据类型,获取与独立存储范围对应的独立存储。Obtains isolated storage corresponding to the isolated storage scope given the application domain and assembly evidence types.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
GetUserStoreForApplication()

获取与调用代码的应用程序标识对应的用户范围的独立存储。Obtains user-scoped isolated storage corresponding to the calling code's application identity.

GetUserStoreForAssembly()

获取与调用代码的程序集标识对应的用户范围的独立存储。Obtains user-scoped isolated storage corresponding to the calling code's assembly identity.

GetUserStoreForDomain()

获取与应用程序域标识和程序集标识对应的用户范围的独立存储。Obtains user-scoped isolated storage corresponding to the application domain identity and assembly identity.

GetUserStoreForSite()

获取用户范围的独立存储,供虚拟主机域中的应用程序使用。Obtains a user-scoped isolated store for use by applications in a virtual host domain.

IncreaseQuotaTo(Int64)

使应用程序显式请求一个更大的配额大小,以字节为单位。Enables an application to explicitly request a larger quota size, in bytes.

InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

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

初始化新的 IsolatedStorage 对象。Initializes a new IsolatedStorage object.

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

初始化新的 IsolatedStorage 对象。Initializes a new IsolatedStorage object.

(继承自 IsolatedStorage)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

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

将指定的目录及其内容移到新位置。Moves a specified directory and its contents to a new location.

MoveFile(String, String)

将指定文件移到新位置,还可以允许你指定新文件名。Moves a specified file to a new location, and optionally lets you specify a new file name.

OpenFile(String, FileMode)

在指定的模式中打开文件。Opens a file in the specified mode.

OpenFile(String, FileMode, FileAccess)

用指定的读/写访问权限在指定模式下打开文件。Opens a file in the specified mode with the specified read/write access.

OpenFile(String, FileMode, FileAccess, FileShare)

用指定的读/写访问权限和共享权限在指定的模式下打开文件。Opens a file in the specified mode, with the specified read/write access and sharing permission.

Remove()

移除独立存储区范围及其所有内容。Removes the isolated storage scope and all its contents.

Remove(IsolatedStorageScope)

为所有标识移除指定的独立存储范围。Removes the specified isolated storage scope for all identities.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅