IsolatedStorageFile 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示包含文件和目录的独立存储区域。
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 |
获取一个值,该值表示用于隔离存储的空间量。 |