Export (0) Print
Expand All

IsolatedStorageFile.GetStore Method (IsolatedStorageScope, Evidence, Type, Evidence, Type)

Obtains isolated storage corresponding to the given application domain and the assembly evidence objects and types.

Namespace:  System.IO.IsolatedStorage
Assembly:  mscorlib (in mscorlib.dll)

public static IsolatedStorageFile GetStore(
	IsolatedStorageScope scope,
	Evidence domainEvidence,
	Type domainEvidenceType,
	Evidence assemblyEvidence,
	Type assemblyEvidenceType
)

Parameters

scope
Type: System.IO.IsolatedStorage.IsolatedStorageScope

A bitwise combination of the enumeration values.

domainEvidence
Type: System.Security.Policy.Evidence

An object that contains the application domain identity.

domainEvidenceType
Type: System.Type

The identity type to choose from the application domain evidence.

assemblyEvidence
Type: System.Security.Policy.Evidence

An object that contains the code assembly identity.

assemblyEvidenceType
Type: System.Type

The identity type to choose from the application code assembly evidence.

Return Value

Type: System.IO.IsolatedStorage.IsolatedStorageFile
An object that represents the parameters.

ExceptionCondition
SecurityException

Sufficient isolated storage permissions have not been granted.

ArgumentNullException

The domainEvidence or assemblyEvidence identity has not been passed in.

ArgumentException

The scope is invalid.

IsolatedStorageException

An isolated storage location cannot be initialized.

-or-

scope contains the enumeration value Application, but the application identity of the caller cannot be determined, because the ActivationContext for the current application domain returned null.

-or-

scope contains the value Domain, but the permissions for the application domain cannot be determined.

-or-

scope contains the value Assembly, but the permissions for the calling assembly cannot be determined.

NoteNote

If the scope parameter is Domain and the application domain in which the assembly is installed does not have IsolatedStorageFilePermission, the GetStore method will return an IsolatedStorageFile object without a quota. Later attempts to create an IsolatedStorageFile object using the IsolatedStorageFile object that does not have a quota will fail with an IsolatedStorageException.

The following code example obtains storage based on publisher evidence.

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 occured: {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);

    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft