FileStream Constructor (String, FileMode, FileAccess, FileShare, Int32)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Initializes a new instance of the FileStream class with the specified path, creation mode, read/write and sharing permission, and buffer size.

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

Syntax

Public Sub New ( _
    path As String, _
    mode As FileMode, _
    access As FileAccess, _
    share As FileShare, _
    bufferSize As Integer _
)
public FileStream(
    string path,
    FileMode mode,
    FileAccess access,
    FileShare share,
    int bufferSize
)

Parameters

  • path
    Type: System..::.String
    A relative or absolute path for the file that the current FileStream object will encapsulate.
  • 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.

Exceptions

Exception Condition
ArgumentNullException

path is nullNothingnullptra null reference (Nothing in Visual Basic).

ArgumentException

path is an empty string (""), contains only white space, or contains one or more invalid characters.

-or-

path refers to a non-file device, such as "con:", "com1:", "lpt1:", etc. in an NTFS environment.

NotSupportedException

path refers to a non-file device, such as "con:", "com1:", "lpt1:", etc. in a non-NTFS environment.

ArgumentException

path is an empty string (""), contains only white space, or contains one or more invalid characters.

ArgumentOutOfRangeException

bufferSize is negative or zero.

-or-

mode, access, or share contain an invalid value.

FileNotFoundException

The file cannot be found, such as when mode is FileMode.Truncate or FileMode.Open, and the file specified by path does not exist. The file must already exist in these modes.

IOException

An I/O error occurs, such as specifying FileMode.CreateNew and the file specified by path already exists.

-or-

The system is running Windows 98 or Windows 98 Second Edition and share is set to FileShare.Delete.

-or-

The stream has been closed.

SecurityException

The caller does not have the required permission.

DirectoryNotFoundException

The specified path is invalid, such as being on an unmapped drive.

UnauthorizedAccessException

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

PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

Remarks

Version Notes

Windows Phone

This member has a SecurityCriticalAttribute attribute. This attribute restricts this member to internal use. Application code that uses this member throws a MethodAccessException.

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Platforms

Windows Phone

See Also

Reference

FileStream Class

FileStream Overload

System.IO Namespace