共用方式為


IsolatedStorageFile.GetUserStoreForDomain 方法

定義

取得對應於應用程式定義域識別和組件識別的使用者範圍隔離儲存區。

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

傳回

對應至 IsolatedStorageScope 的物件,該物件以應用程式定義域識別和組件識別的組合為基礎。

例外狀況

尚未授與足夠的隔離儲存區使用權限。

無法開啟存放區。

-或-

指定組件沒有足夠的使用權限建立隔離存放區。

-或-

無法初始化隔離的儲存區位置。

-或-

無法判斷應用程式定義域的使用權限。

範例

下列程式代碼範例示範 GetUserStoreForDomain 方法。 如需此範例的完整內容,請參閱概 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

備註

在不同應用程式的內容中使用時,相同的元件程式代碼會使用不同的隔離存放區。

GetUserStoreForDomain 在功能上相當於下列程式代碼:

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)

在相同應用程式域內執行的不同元件一律具有不同的隔離存放區。

注意

GetUserStoreForDomain如果安裝元件的應用程式域沒有 IsolatedStorageFilePermission,則會傳回IsolatedStorageFile沒有配額的物件。 稍後嘗試使用IsolatedStorageFile沒有配額的物件來建立 IsolatedStorageFile 物件,將會失敗。IsolatedStorageException

適用於

另請參閱