FileStream Constructor (String, FileMode, FileAccess)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

When it is called by trusted applications, initializes a new instance of the FileStream class with the specified path, creation mode, and read/write permission.

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

Syntax

'Declaration
<SecuritySafeCriticalAttribute> _
Public Sub New ( _
    path As String, _
    mode As FileMode, _
    access As FileAccess _
)
[SecuritySafeCriticalAttribute]
public FileStream(
    string path,
    FileMode mode,
    FileAccess access
)

Parameters

  • path
    Type: System.String
    A relative or absolute path for the file that the current FileStream object will encapsulate.

Exceptions

Exception Condition
ArgumentNullException

path is nulla 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.

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 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.

ArgumentOutOfRangeException

mode contains an invalid value.

Remarks

Platform Notes

Silverlight for Windows Phone Silverlight for Windows Phone

 This member has a SecurityCriticalAttribute attribute on Silverlight for Windows Phone, because the attribute was present in Silverlight 3. This attribute restricts this member to internal use. Application code that uses this member throws a MethodAccessException.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.