IsolatedStorageFileStream.Handle プロパティ
現在の IsolatedStorageFileStream オブジェクトによってカプセル化されるファイルのファイル ハンドルを取得します。 IsolatedStorageFileStream ではこのプロパティへのアクセスは許可されておらず、 IsolatedStorageException がスローされます。
Overrides Public ReadOnly Property Handle As IntPtr
[C#]
public override IntPtr Handle {get;}
[C++]
public: __property IntPtr get_Handle();
[JScript]
public override function get Handle() : IntPtr;
プロパティ値
現在の IsolatedStorageFileStream オブジェクトによってカプセル化されるファイルのファイル ハンドル。
例外
例外の種類 | 条件 |
---|---|
IsolatedStorageException | プロパティがアクセスされました。 |
解説
詳細については、「 Handle 」を参照してください。
使用例
[Visual Basic, C#, C++] Handle プロパティのコード例を次に示します。
Private Function GetPrefsForUser() As Boolean
Try
' Retrieve an IsolatedStorageFile for the current Domain and Assembly.
Dim isoFile As IsolatedStorageFile = _
IsolatedStorageFile.GetStore(IsolatedStorageScope.User _
Or IsolatedStorageScope.Assembly _
Or IsolatedStorageScope.Domain, Nothing, Nothing)
Dim isoStream As New IsolatedStorageFileStream(Me.userName, FileMode.Open, _
FileAccess.Read, FileShare.Read)
' farThe code executes to this point only if a file corresponding to the username exists.
' Though you can perform operations on the stream, you cannot get a handle to the file.
Try
Dim aFileHandle As IntPtr = isoStream.Handle
Console.WriteLine(("A pointer to a file handle has been obtained. " & aFileHandle.ToString() & " " & aFileHandle.GetHashCode()))
Catch ex As Exception
' Handle the exception.
Console.WriteLine("Expected exception")
Console.WriteLine(ex.ToString())
End Try
Dim reader As New StreamReader(isoStream)
' Read the data.
Me.NewsUrl = reader.ReadLine()
Me.SportsUrl = reader.ReadLine()
reader.Close()
isoFile.Close()
Return False
Catch ex As System.IO.FileNotFoundException
' Expected exception if a file cannot be found. This indicates that we have a new user.
Return True
End Try
End Function 'GetPrefsForUser
[C#]
private bool GetPrefsForUser()
{
try
{
// Retrieve an IsolatedStorageFile for the current Domain and Assembly.
IsolatedStorageFile isoFile =
IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Assembly |
IsolatedStorageScope.Domain ,
null,
null);
IsolatedStorageFileStream isoStream =
new IsolatedStorageFileStream( this.userName,
FileMode.Open,
FileAccess.Read,
FileShare.Read);
// The code executes to this point only if a file corresponding to the username exists.
// Though you can perform operations on the stream, you cannot get a handle to the file.
try
{
IntPtr aFileHandle = isoStream.Handle;
Console.WriteLine("A pointer to a file handle has been obtained. "
+ aFileHandle.ToString() + " "
+ aFileHandle.GetHashCode());
}
catch (Exception e)
{
// Handle the exception.
Console.WriteLine("Expected exception");
Console.WriteLine(e);
}
StreamReader reader = new StreamReader(isoStream);
// Read the data.
this.NewsUrl = reader.ReadLine();
this.SportsUrl = reader.ReadLine();
reader.Close();
isoFile.Close();
return false;
}
catch (System.IO.FileNotFoundException)
{
// Expected exception if a file cannot be found. This indicates that we have a new user.
return true;
}
}
[C++]
bool GetPrefsForUser()
{
try
{
// Retrieve an IsolatedStorageFile for the current Domain and Assembly.
IsolatedStorageFile* isoFile =
IsolatedStorageFile::GetStore(
static_cast<IsolatedStorageScope>(IsolatedStorageScope::User |
IsolatedStorageScope::Assembly |
IsolatedStorageScope::Domain),
(Type*)0, 0);
IsolatedStorageFileStream* isoStream = new IsolatedStorageFileStream(this->userName,
FileMode::Open,
FileAccess::ReadWrite,
isoFile);
// farThe code executes to this point only if a file corresponding to the username exists.
// Though you can perform operations on the stream, you cannot get a handle to the file.
try
{
IntPtr aFileHandle = isoStream->Handle;
Console::WriteLine(S"A pointer to a file handle has been obtained. {0} {1}",
__box(aFileHandle), __box(aFileHandle.GetHashCode()));
}
catch (Exception* e)
{
// Handle the exception.
Console::WriteLine(S"Expected exception");
Console::WriteLine(e->ToString());
}
StreamReader* reader = new StreamReader(isoStream);
// Read the data.
this->NewsUrl = reader->ReadLine();
this->SportsUrl = reader->ReadLine();
reader->Close();
isoFile->Close();
isoStream->Close();
return false;
}
catch (Exception* e)
{
// Expected exception if a file cannot be found. This indicates that we have a new user.
String* errorMessage = e->ToString();
return true;
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
.NET Framework セキュリティ:
- SecurityPermission (アンマネージ コードにアクセスするために必要な許可)。 SecurityPermissionFlag.UnmanagedCode (関連する列挙体)
参照
IsolatedStorageFileStream クラス | IsolatedStorageFileStream メンバ | System.IO.IsolatedStorage 名前空間