Export (0) Print
Expand All

FileStream.FileStream(IntPtr, FileAccess, Boolean) Constructor

NOTE: This constructor is now obsolete.

Initializes a new instance of the FileStream class for the specified file handle, with the specified read/write permission and FileStream instance ownership.

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)

[ObsoleteAttribute(L"This constructor has been deprecated.  Please use new FileStream(SafeFileHandle handle, FileAccess access) instead, and optionally make a new SafeFileHandle with ownsHandle=false if needed.  http://go.microsoft.com/fwlink/?linkid=14202")] 
public:
FileStream (
	IntPtr handle, 
	FileAccess access, 
	bool ownsHandle
)
/** @attribute ObsoleteAttribute("This constructor has been deprecated.  Please use new FileStream(SafeFileHandle handle, FileAccess access) instead, and optionally make a new SafeFileHandle with ownsHandle=false if needed.  http://go.microsoft.com/fwlink/?linkid=14202") */ 
public FileStream (
	IntPtr handle, 
	FileAccess access, 
	boolean ownsHandle
)
ObsoleteAttribute("This constructor has been deprecated.  Please use new FileStream(SafeFileHandle handle, FileAccess access) instead, and optionally make a new SafeFileHandle with ownsHandle=false if needed.  http://go.microsoft.com/fwlink/?linkid=14202") 
public function FileStream (
	handle : IntPtr, 
	access : FileAccess, 
	ownsHandle : boolean
)
Not applicable.

Parameters

handle

A file handle for the file that the current FileStream object will encapsulate.

access

A FileAccess constant that gets the CanRead and CanWrite properties of the FileStream object.

ownsHandle

true if the file handle will be owned by this FileStream instance; otherwise, false.

Exception typeCondition

ArgumentException

access is not a field of FileAccess.

SecurityException

The caller does not have the required permission.

IOException

An I/O error occurs, such as a disk error.

-or-

The stream has been closed.

UnauthorizedAccessException

The access requested is not permitted by the operating system for the specified file handle, such as when access is Write or ReadWrite and the file handle is set for read-only access.

The FileStream object is given the specified access to the file. The ownership of the handle will be as specified. If this process owns the handle, a call to the Close method will also close the handle and the file's handle count is decremented. The FileStream object is given the default buffer size of 8192 bytes.

FileStream assumes that it has exclusive control over the handle. Reading, writing, or seeking while a FileStream is also holding a handle could result in data corruption. For data safety, call Flush before using the handle, and avoid calling methods other than Close after you are done using the handle.

FileShare.Read is the default for those FileStream constructors without a FileShare parameter.

Caution noteCaution:

When you compile a set of characters with a particular cultural setting and retrieve those same characters with a different cultural setting, the characters might not be interpretable, and could cause an exception to be thrown.

For a list of common I/O tasks, see Common I/O Tasks.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 1.0, 1.1, 2.0
Obsolete (compiler warning) in 3.0

Community Additions

ADD
Show:
© 2014 Microsoft