IsolatedStorageFileStream.Handle 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
注意
This property has been deprecated. Please use IsolatedStorageFileStream's SafeFileHandle property instead. https://go.microsoft.com/fwlink/?linkid=14202
注意
IsolatedStorageFileStream.Handle has been deprecated. Use IsolatedStorageFileStream's SafeFileHandle property instead.
注意
This property has been deprecated. Please use IsolatedStorageFileStream's SafeFileHandle property instead. http://go.microsoft.com/fwlink/?linkid=14202
获取当前 IsolatedStorageFileStream 对象封装的文件的文件句柄。 不允许在 IsolatedStorageFileStream 对象上访问此属性,如果访问,将引发 IsolatedStorageException。
public:
virtual property IntPtr Handle { IntPtr get(); };
[System.Obsolete("This property has been deprecated. Please use IsolatedStorageFileStream's SafeFileHandle property instead. https://go.microsoft.com/fwlink/?linkid=14202")]
public override IntPtr Handle { get; }
[System.Obsolete("IsolatedStorageFileStream.Handle has been deprecated. Use IsolatedStorageFileStream's SafeFileHandle property instead.")]
public override IntPtr Handle { get; }
[System.Obsolete("This property has been deprecated. Please use IsolatedStorageFileStream's SafeFileHandle property instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public override IntPtr Handle { get; }
public override IntPtr Handle { get; }
[System.Obsolete("This property has been deprecated. Please use IsolatedStorageFileStream's SafeFileHandle property instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public override IntPtr Handle { [System.Security.SecurityCritical] get; }
[<System.Obsolete("This property has been deprecated. Please use IsolatedStorageFileStream's SafeFileHandle property instead. https://go.microsoft.com/fwlink/?linkid=14202")>]
member this.Handle : nativeint
[<System.Obsolete("IsolatedStorageFileStream.Handle has been deprecated. Use IsolatedStorageFileStream's SafeFileHandle property instead.")>]
member this.Handle : nativeint
[<System.Obsolete("This property has been deprecated. Please use IsolatedStorageFileStream's SafeFileHandle property instead. http://go.microsoft.com/fwlink/?linkid=14202")>]
member this.Handle : nativeint
member this.Handle : nativeint
[<System.Obsolete("This property has been deprecated. Please use IsolatedStorageFileStream's SafeFileHandle property instead. http://go.microsoft.com/fwlink/?linkid=14202")>]
[<get: System.Security.SecurityCritical>]
member this.Handle : nativeint
Public Overrides ReadOnly Property Handle As IntPtr
属性值
nativeint
当前 IsolatedStorageFileStream 对象封装的文件的文件句柄。
- 属性
例外
Handle 属性始终生成此异常。
示例
下面的代码示例演示 了 Handle 属性。
[SecurityPermissionAttribute(SecurityAction::Demand, Flags=SecurityPermissionFlag::UnmanagedCode)]
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^)nullptr, nullptr );
IsolatedStorageFileStream^ isoStream = gcnew 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( "A pointer to a file handle has been obtained. {0} {1}", aFileHandle, aFileHandle.GetHashCode() );
}
catch ( Exception^ e )
{
// Handle the exception.
Console::WriteLine( "Expected exception" );
Console::WriteLine( e->ToString() );
}
StreamReader^ reader = gcnew 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;
}
}
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("substituteUsername",
System.IO.FileMode.Open,
System.IO.FileAccess.Read,
System.IO.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
{
SafeFileHandle aFileHandle = isoStream.SafeFileHandle;
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;
}
}
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("substituteUsername", System.IO.FileMode.Open, _
System.IO.FileAccess.Read, System.IO.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 SafeFileHandle = isoStream.SafeFileHandle
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
注解
有关详细信息,请参阅 Handle。