IsolatedStorageFile.GetMachineStoreForDomain 方法

定义

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

C#
public static System.IO.IsolatedStorage.IsolatedStorageFile GetMachineStoreForDomain();

返回

与基于应用程序域标识和程序集标识组合的 IsolatedStorageScope 对应的对象。

例外

未授予使用独立存储的足够权限。

存储区未能打开。

- 或 -

指定的程序集没有足够的权限创建独立存储区。

- 或 -

不能确定应用程序域的权限。

- 或 -

无法初始化独立的存储位置。

示例

下面的代码示例演示 GetUserStoreForDomain 了 方法。 有关此示例的完整上下文,请参阅 IsolatedStorageFile 概述。

C#
IsolatedStorageFile isoFile;
isoFile = IsolatedStorageFile.GetUserStoreForDomain();

// Open or create a writable file.
IsolatedStorageFileStream isoStream =
    new IsolatedStorageFileStream(this.userName,
    FileMode.OpenOrCreate,
    FileAccess.Write,
    isoFile);

StreamWriter writer = new StreamWriter(isoStream);
writer.WriteLine(this.NewsUrl);
writer.WriteLine(this.SportsUrl);
// Calculate the amount of space used to record the user's preferences.
double d = isoFile.CurrentSize / isoFile.MaximumSize;
Console.WriteLine("CurrentSize = " + isoFile.CurrentSize.ToString());
Console.WriteLine("MaximumSize = " + isoFile.MaximumSize.ToString());
// StreamWriter.Close implicitly closes isoStream.
writer.Close();
isoFile.Dispose();
isoFile.Close();
return d;

注解

当在不同的应用程序的上下文中使用时,同一程序集代码将使用不同的独立存储。

GetMachineStoreForDomain 在功能上等效于以下代码:

C#
isoFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.Assembly |
    IsolatedStorageScope.Domain | IsolatedStorageScope.Machine,
    null, null);

在同一应用程序域中运行的不同程序集始终具有不同的独立存储。

备注

GetUserStoreForDomain如果安装程序集的应用程序域没有 IsolatedStorageFilePermission,将返回一个IsolatedStorageFile没有配额的对象。 稍后尝试使用IsolatedStorageFile没有配额的 对象创建 IsolatedStorageFile 对象将失败,并显示 IsolatedStorageException

适用于

产品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

另请参阅