다음을 통해 공유


방법: 격리된 스토리지의 저장소 가져오기

격리된 저장소는 데이터 구획 내에서 가상 파일 시스템을 노출합니다. IsolatedStorageFile 클래스는 격리된 저장소와 상호 작용하는 데 필요한 여러 가지 메서드를 제공합니다. 저장소를 만들고 검색하기 위해 IsolatedStorageFile은 세 가지 정적 메서드를 제공합니다.

  • GetUserStoreForAssembly는 사용자와 어셈블리별로 격리된 스토리지를 반환합니다.

  • GetUserStoreForDomain은 도메인과 어셈블리별로 격리된 스토리지를 반환합니다.

    이 두 메서드는 모두 자신이 호출되는 코드에 속하는 저장소를 검색합니다.

  • 정적 메서드 GetStore는 범위 매개 변수의 조합을 전달하여 지정된 격리된 저장소를 반환합니다.

다음 코드는 사용자, 어셈블리 및 도메인별로 격리된 저장소를 반환합니다.

IsolatedStorageFile^ isoStore = IsolatedStorageFile::GetStore(IsolatedStorageScope::User |
    IsolatedStorageScope::Assembly | IsolatedStorageScope::Domain, (Type ^)nullptr, (Type ^)nullptr);
IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
    IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain, null, null);
Dim isoStore As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or
    IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, Nothing, Nothing)

GetStore 메서드를 사용하여 로밍 사용자 프로필과 함께 저장소를 로밍하도록 지정할 수 있습니다. 이를 설정하는 방법에 대한 자세한 내용은 격리 유형을 참조하세요.

다른 어셈블리 내에서 얻은 격리된 저장소는 기본적으로 서로 다른 저장소입니다. 어셈블리 또는 도메인 증명을 GetStore 메서드의 매개 변수에서 전달하여 다른 어셈블리 또는 도메인의 저장소에 액세스할 수 있습니다. 그렇게 하려면 애플리케이션 도메인 ID별로 격리된 스토리지에 액세스할 수 있는 권한이 필요합니다. 자세한 내용은 GetStore 메서드 오버로드를 참조하십시오.

GetUserStoreForAssemblyGetUserStoreForDomainGetStore 메서드는 IsolatedStorageFile 개체를 반환합니다. 상황에 가장 적합한 격리 유형을 결정하는 데 도움을 받으려면 격리 유형을 참조하세요. 격리된 스토리지 파일 개체가 있으면 격리된 스토리지 메서드를 사용하여 파일과 디렉터리를 읽고 쓰고 만들고 삭제하는 작업을 수행할 수 있습니다.

코드가 저장소 자체를 가져올 수 있는 액세스 권한이 충분하지 않은 코드에 IsolatedStorageFile 개체를 전달하지 못하도록 하는 메커니즘은 없습니다. 도메인 및 어셈블리 ID 및 격리된 스토리지 권한은 IsolatedStorage 개체에 대한 참조를 일반적으로 GetUserStoreForAssembly, GetUserStoreForDomain 또는 GetStore 메서드에서 가져온 경우에만 검사됩니다. 따라서 IsolatedStorageFile 개체에 대한 참조를 보호하는 것은 이러한 참조를 사용하는 코드의 책임입니다.

예시

다음 코드에서는 사용자 및 어셈블리별로 격리된 저장소를 가져오는 클래스의 간단한 예제를 제공합니다. IsolatedStorageScope.Domain 메서드가 전달하는 인수에 GetStore을 추가하면 사용자, 도메인 및 어셈블리별로 격리된 저장소를 검색하도록 코드를 변경할 수 있습니다.

코드를 실행한 후 명령줄에 StoreAdm /LIST를 입력하여 저장소가 생성되었는지 확인할 수 있습니다. 이렇게 하면 격리된 스토리지 도구(Storeadm.exe)가 실행되어 사용자에 대해 현재 격리된 저장소가 모두 나열됩니다.

using namespace System;
using namespace System::IO::IsolatedStorage;

public ref class ObtainingAStore
{
public:
    static void Main()
    {
        // Get a new isolated store for this assembly and put it into an
        // isolated store object.

        IsolatedStorageFile^ isoStore = IsolatedStorageFile::GetStore(IsolatedStorageScope::User |
            IsolatedStorageScope::Assembly, (Type ^)nullptr, (Type ^)nullptr);
    }
};
using System;
using System.IO.IsolatedStorage;

public class ObtainingAStore
{
    public static void Main()
    {
        // Get a new isolated store for this assembly and put it into an
        // isolated store object.

        IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
            IsolatedStorageScope.Assembly, null, null);
    }
}
Imports System.IO.IsolatedStorage

Public Class ObtainingAStore
    Public Shared Sub Main()
        ' Get a new isolated store for this assembly and put it into an
        ' isolated store object.

        Dim isoStore As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or
            IsolatedStorageScope.Assembly, Nothing, Nothing)
    End Sub
End Class

참고 항목