IsolatedStorageFile.GetUserStoreForDomain Metoda

Definicja

Uzyskuje magazyn izolowany o zakresie użytkownika odpowiadający tożsamości domeny aplikacji i tożsamości zestawu.

public:
 static System::IO::IsolatedStorage::IsolatedStorageFile ^ GetUserStoreForDomain();
public static System.IO.IsolatedStorage.IsolatedStorageFile GetUserStoreForDomain ();
static member GetUserStoreForDomain : unit -> System.IO.IsolatedStorage.IsolatedStorageFile
Public Shared Function GetUserStoreForDomain () As IsolatedStorageFile

Zwraca

Obiekt odpowiadający elementowi IsolatedStorageScope, na podstawie kombinacji tożsamości domeny aplikacji i tożsamości zestawu.

Wyjątki

Nie udzielono wystarczających izolowanych uprawnień magazynu.

Nie można otworzyć magazynu.

-lub-

Określony zestaw ma niewystarczające uprawnienia do tworzenia izolowanych magazynów.

-lub-

Nie można zainicjować izolowanej lokalizacji magazynu.

-lub-

Nie można określić uprawnień dla domeny aplikacji.

Przykłady

Poniższy przykład kodu przedstawia metodę GetUserStoreForDomain . Pełny kontekst tego przykładu zawiera omówienie IsolatedStorageFile .

IsolatedStorageFile^ isoFile;
isoFile = IsolatedStorageFile::GetUserStoreForDomain();

// Open or create a writable file.
IsolatedStorageFileStream^ isoStream = gcnew IsolatedStorageFileStream( this->userName,FileMode::OpenOrCreate,FileAccess::Write,isoFile );
StreamWriter^ writer = gcnew 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 = {0}", isoFile->CurrentSize.ToString() );
Console::WriteLine( "MaximumSize = {0}", isoFile->MaximumSize.ToString() );
writer->Close();
isoFile->Close();
isoStream->Close();
return d;
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;
Dim isoFile As IsolatedStorageFile
isoFile = IsolatedStorageFile.GetUserStoreForDomain()

' Open or create a writable file.
Dim isoStream As New IsolatedStorageFileStream(Me.userName, FileMode.OpenOrCreate, _
    FileAccess.Write, isoFile)

Dim writer As New StreamWriter(isoStream)
writer.WriteLine(Me.NewsUrl)
writer.WriteLine(Me.SportsUrl)
' Calculate the amount of space used to record the user's preferences.
Dim d As Double = Convert.ToDouble(isoFile.CurrentSize) / Convert.ToDouble(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

Uwagi

Ten sam kod zestawu będzie używać różnych izolowanych magazynów, gdy są używane w kontekście różnych aplikacji.

GetUserStoreForDomain jest funkcjonalnie równoważny z następującym kodem:

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

Różne zestawy działające w tej samej domenie aplikacji zawsze mają odrębne izolowane magazyny.

Uwaga

GetUserStoreForDomainIsolatedStorageFile zwróci obiekt bez limitu przydziału, jeśli domena aplikacji, w której zainstalowano zestaw, nie ma IsolatedStorageFilePermission. Później próbuje utworzyć IsolatedStorageFile obiekt przy użyciu IsolatedStorageFile obiektu, który nie ma limitu przydziału, zakończy się niepowodzeniem z elementem IsolatedStorageException.

Dotyczy

Zobacz też