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

适用于

另请参阅