IsolatedStorageFile.GetStore 方法

定义

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

重载

GetStore(IsolatedStorageScope, Object)

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

GetStore(IsolatedStorageScope, Type)

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

GetStore(IsolatedStorageScope, Object, Object)

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

GetStore(IsolatedStorageScope, Type, Type)

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

GetStore(IsolatedStorageScope, Evidence, Type, Evidence, Type)

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

GetStore(IsolatedStorageScope, Object)

Source:
IsolatedStorageFile.cs
Source:
IsolatedStorageFile.cs
Source:
IsolatedStorageFile.cs

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

C#
public static System.IO.IsolatedStorage.IsolatedStorageFile GetStore (System.IO.IsolatedStorage.IsolatedStorageScope scope, object? applicationIdentity);
C#
public static System.IO.IsolatedStorage.IsolatedStorageFile GetStore (System.IO.IsolatedStorage.IsolatedStorageScope scope, object applicationIdentity);

参数

scope
IsolatedStorageScope

枚举值的按位组合。

applicationIdentity
Object

包含应用程序标识证据的对象。

返回

表示这些参数的对象。

例外

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

applicationIdentity尚未传入标识。

scope 无效。

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

- 或 -

scope 包含 枚举值 Application,但无法确定调用方的应用程序标识,因为 ActivationContext 当前应用程序域的 返回了 null

- 或 -

scope 包含值 Domain,但不能确定应用程序域的权限。

- 或 -

scope 包含值 Assembly,但不能确定调用程序集的权限。

注解

备注

scope如果 参数为 IsolatedStorageScope.Application ,并且安装程序集的应用程序域没有 IsolatedStorageFilePermission,则 GetStore 该方法将返回一个IsolatedStorageFile没有配额的对象。 稍后尝试使用IsolatedStorageFile没有配额的 对象创建 IsolatedStorageFile 对象将失败,并显示 IsolatedStorageException

另请参阅

适用于

.NET 9 和其他版本
产品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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

GetStore(IsolatedStorageScope, Type)

Source:
IsolatedStorageFile.cs
Source:
IsolatedStorageFile.cs
Source:
IsolatedStorageFile.cs

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

C#
public static System.IO.IsolatedStorage.IsolatedStorageFile GetStore (System.IO.IsolatedStorage.IsolatedStorageScope scope, Type? applicationEvidenceType);
C#
public static System.IO.IsolatedStorage.IsolatedStorageFile GetStore (System.IO.IsolatedStorage.IsolatedStorageScope scope, Type applicationEvidenceType);

参数

scope
IsolatedStorageScope

枚举值的按位组合。

applicationEvidenceType
Type

包含应用程序标识的对象。

返回

表示这些参数的对象。

例外

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

applicationEvidence尚未传入标识。

scope 无效。

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

- 或 -

scope 包含 枚举值 Application,但无法确定调用方的应用程序标识,因为 ActivationContext 当前应用程序域的 返回了 null

- 或 -

scope 包含值 Domain,但不能确定应用程序域的权限。

- 或 -

scope 包含值 Assembly,但不能确定调用程序集的权限。

注解

备注

scope如果 参数为 Application ,并且安装程序集的应用程序域没有 IsolatedStorageFilePermission,则 GetStore 该方法将返回一个IsolatedStorageFile没有配额的对象。 稍后尝试使用IsolatedStorageFile没有配额的 对象创建 IsolatedStorageFile 对象将失败,并显示 IsolatedStorageException

另请参阅

适用于

.NET 9 和其他版本
产品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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

GetStore(IsolatedStorageScope, Object, Object)

Source:
IsolatedStorageFile.cs
Source:
IsolatedStorageFile.cs
Source:
IsolatedStorageFile.cs

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

C#
public static System.IO.IsolatedStorage.IsolatedStorageFile GetStore (System.IO.IsolatedStorage.IsolatedStorageScope scope, object? domainIdentity, object? assemblyIdentity);
C#
public static System.IO.IsolatedStorage.IsolatedStorageFile GetStore (System.IO.IsolatedStorage.IsolatedStorageScope scope, object domainIdentity, object assemblyIdentity);

参数

scope
IsolatedStorageScope

枚举值的按位组合。

domainIdentity
Object

包含应用程序域标识的证据的对象。

assemblyIdentity
Object

包含代码程序集标识的证据的对象。

返回

表示这些参数的对象。

例外

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

既不传递 domainIdentity,也不传递 assemblyIdentity。 这将验证使用的是正确的构造函数。

- 或 -

domainIdentityassemblyIdentitynull

scope 无效。

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

- 或 -

scope 包含 枚举值 Application,但无法确定调用方的应用程序标识,因为 ActivationContext 当前应用程序域的 返回了 null

- 或 -

scope 包含值 Domain,但不能确定应用程序域的权限。

- 或 -

scope 包含值 Assembly,但不能确定调用程序集的权限。

注解

对于需要像打开另一个程序集一样打开存储区的管理代码,这种形式的 GetStore 最有用。 存储区是为提供的证据打开的,而不是针对当前正在执行的程序集打开的。

备注

scope如果 参数为 Domain ,并且安装程序集的应用程序域没有 IsolatedStorageFilePermission,则 GetStore 该方法将返回一个IsolatedStorageFile没有配额的对象。 稍后尝试使用IsolatedStorageFile没有配额的 对象创建 IsolatedStorageFile 对象将失败,并显示 IsolatedStorageException

另请参阅

适用于

.NET 9 和其他版本
产品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 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

GetStore(IsolatedStorageScope, Type, Type)

Source:
IsolatedStorageFile.cs
Source:
IsolatedStorageFile.cs
Source:
IsolatedStorageFile.cs

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

C#
public static System.IO.IsolatedStorage.IsolatedStorageFile GetStore (System.IO.IsolatedStorage.IsolatedStorageScope scope, Type? domainEvidenceType, Type? assemblyEvidenceType);
C#
public static System.IO.IsolatedStorage.IsolatedStorageFile GetStore (System.IO.IsolatedStorage.IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType);

参数

scope
IsolatedStorageScope

枚举值的按位组合。

domainEvidenceType
Type

可从调用应用程序的域内存在的 Evidence 列表中选择的 Evidence 的类型。 如果为 null,则允许 IsolatedStorage 对象选择证据。

assemblyEvidenceType
Type

可从调用应用程序的域内存在的 Evidence 列表中选择的 Evidence 的类型。 如果为 null,则允许 IsolatedStorage 对象选择证据。

返回

表示这些参数的对象。

例外

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

scope 无效。

所提供的证据类型没有出现在程序集证据列表中。

- 或 -

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

- 或 -

scope 包含 枚举值 Application,但无法确定调用方的应用程序标识,因为 ActivationContext 当前应用程序域的 返回了 null

- 或 -

scope 包含值 Domain,但不能确定应用程序域的权限。

- 或 -

scope 包含 Assembly,但不能决定调用程序集的权限。

示例

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

C#

// Retrieve an IsolatedStorageFile for the current Domain and Assembly.
IsolatedStorageFile isoFile =
    IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
    IsolatedStorageScope.Assembly |
    IsolatedStorageScope.Domain,
    null,
    null);

IsolatedStorageFileStream isoStream =
    new IsolatedStorageFileStream("substituteUsername",
    System.IO.FileMode.Open,
    System.IO.FileAccess.Read,
     System.IO.FileShare.Read);

注解

这是最有可能从应用程序代码调用的 GetStore 重载。

GetStore 此重载为传入的证据类型打开一个独立存储。

备注

scope如果 参数为 Domain ,并且安装程序集的应用程序域没有 IsolatedStorageFilePermission,则 GetStore 该方法将返回一个IsolatedStorageFile没有配额的对象。 稍后尝试使用IsolatedStorageFile没有配额的 对象创建 IsolatedStorageFile 对象将失败,并显示 IsolatedStorageException

另请参阅

适用于

.NET 9 和其他版本
产品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 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

GetStore(IsolatedStorageScope, Evidence, Type, Evidence, Type)

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

C#
public static System.IO.IsolatedStorage.IsolatedStorageFile GetStore (System.IO.IsolatedStorage.IsolatedStorageScope scope, System.Security.Policy.Evidence domainEvidence, Type domainEvidenceType, System.Security.Policy.Evidence assemblyEvidence, Type assemblyEvidenceType);

参数

scope
IsolatedStorageScope

枚举值的按位组合。

domainEvidence
Evidence

包含应用程序域标识的对象。

domainEvidenceType
Type

要从应用程序域证据中选择的标识类型。

assemblyEvidence
Evidence

包含代码程序集标识的对象。

assemblyEvidenceType
Type

要从应用程序代码程序集证据中选择的标识类型。

返回

表示这些参数的对象。

例外

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

尚未传入 domainEvidenceassemblyEvidence 标识。

scope 无效。

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

- 或 -

scope 包含 枚举值 Application,但无法确定调用方的应用程序标识,因为 ActivationContext 当前应用程序域的 返回了 null

- 或 -

scope 包含值 Domain,但不能确定应用程序域的权限。

- 或 -

scope 包含值 Assembly,但不能确定调用程序集的权限。

示例

下面的代码示例基于发布者证据获取存储。

C#
using System;
using System.IO;
using System.IO.IsolatedStorage;
using System.Security;
using System.Security.Policy;
using System.Security.Permissions;
using System.Security.Cryptography.X509Certificates;

class Program
{
    static void Main(string[] args)
    {
        try
        {

            if (Test())
            {
                Console.WriteLine("PASSED.");
                Environment.ExitCode = 100;
            }
            else
            {
                Console.WriteLine("FAILED.");
                Environment.ExitCode = 101;
            }
        }
        catch (Exception e)
        {
            Console.Write("Exception occurred: {0}", e.ToString());
            Environment.ExitCode = 101;
        }
        return;
    }

    public static Boolean Test()
    {
        Boolean bRes = true;

        Evidence evidence1 = GetTestEvidence();
        Evidence evidence2 = GetTestEvidence();

        IsolatedStorageFile isf = IsolatedStorageFile.GetStore(
                                    IsolatedStorageScope.User | IsolatedStorageScope.Assembly,
                                    evidence1,
                                    typeof(System.Security.Policy.Publisher),
                                    evidence2,
                                    typeof(System.Security.Policy.Publisher));

        IsolatedStorageFileStream isfs = new IsolatedStorageFileStream("AdminEvd1.testfile", FileMode.OpenOrCreate, isf);
        isfs.WriteByte(5);
        isfs.Flush();
        isfs.Close();

        return bRes;
    }

    public static Evidence GetTestEvidence()
    {
        // For demonsration purposes, use a blank certificate.
        Publisher pub = new Publisher(new X509Certificate(new Byte[64]));
        Object[] arrObj = new Object[1];
        arrObj[0] = (Object)pub;
        return new Evidence(arrObj, arrObj);
    }
}

注解

备注

scope如果 参数为 Domain ,并且安装程序集的应用程序域没有 IsolatedStorageFilePermission,则 GetStore 该方法将返回一个IsolatedStorageFile没有配额的对象。 稍后尝试使用IsolatedStorageFile没有配额的 对象创建 IsolatedStorageFile 对象将失败,并显示 IsolatedStorageException

另请参阅

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.NET Framework 1.1, 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