Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

FileStream Constructor (IntPtr, FileAccess, Boolean, Int32)

Note: This API is now obsolete.

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

Namespace:  System.IO
Assembly:  mscorlib (in mscorlib.dll)
[ObsoleteAttribute("This constructor has been deprecated.  Please use new FileStream(SafeFileHandle handle, FileAccess access, int bufferSize) 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,
	int bufferSize
)

Parameters

handle
Type: System.IntPtr

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

access
Type: System.IO.FileAccess

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

ownsHandle
Type: System.Boolean

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

bufferSize
Type: System.Int32

A positive Int32 value greater than 0 indicating the buffer size. For bufferSize values between one and eight, the actual buffer size is set to eight bytes.

ExceptionCondition
ArgumentOutOfRangeException

bufferSize is negative.

IOException

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

-or-

The stream has been closed.

SecurityException

The caller does not have the required permission.

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 FileStream owns the handle, a call to the Close method will also close the handle. In particular, the file's handle count is decremented. The FileStream object is given the specified buffer size.

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 any methods other than Close after you are done using the handle. Alternately, read and write to the handle before calling this FileStream constructor.

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 file and directory operations, see Common I/O Tasks.

.NET Framework

Supported in: 1.1, 1.0
Obsolete (compiler warning) in 4.5.1
Obsolete (compiler warning) in 4.5
Obsolete (compiler warning) in 4
Obsolete (compiler warning) in 3.5
Obsolete (compiler warning) in 3.5 SP1
Obsolete (compiler warning) in 3.0
Obsolete (compiler warning) in 3.0 SP1
Obsolete (compiler warning) in 3.0 SP2
Obsolete (compiler warning) in 2.0
Obsolete (compiler warning) in 2.0 SP1
Obsolete (compiler warning) in 2.0 SP2

.NET Framework Client Profile

Obsolete (compiler warning) in 4
Obsolete (compiler warning) in 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.