NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

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

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

[Visual Basic]
Overloads Public Sub New( _
   ByVal path As String, _
   ByVal mode As FileMode, _
   ByVal access As FileAccess, _
   ByVal share As FileShare, _
   ByVal bufferSize As Integer _
)
[C#]
public FileStream(
   string path,
   FileMode mode,
   FileAccess access,
   FileShare share,
   int bufferSize
);
[C++]
public: FileStream(
   String* path,
   FileMode mode,
   FileAccess access,
   FileShare share,
   int bufferSize
);
[JScript]
public function FileStream(
   path : String,
   mode : FileMode,
   access : FileAccess,
   share : FileShare,
   bufferSize : int
);

Parameters

path
A relative or absolute path for the file that the current FileStream object will encapsulate.
mode
A FileMode constant that determines how the file is opened or created.
access
A FileAccess constant that determines how the file may be accessed by the FileStream object. This sets the CanRead and CanWrite properties of the FileStream object. CanSeek is set to true if path specifies a disk file.
share
A FileShare constant that determines how the file will be shared by processes.
bufferSize
The desired buffer size in bytes. For bufferSize values between zero and eight, the actual buffer size is set to 8 bytes.

Exceptions

Exception Type Condition
ArgumentNullException path is null.
ArgumentException path is an empty string.
ArgumentOutOfRangeException mode is not a field of FileMode.
ArgumentOutOfRangeException access is not a field of FileAccess.
ArgumentOutOfRangeException share is not a field of FileShare.
ArgumentOutOfRangeException bufferSize is not positive.
FileNotFoundException The file cannot be found. For example, the exception is thrown if mode is FileMode.Truncate, and the file specified by path does not exist. The file must already exist in this mode. In addition, this exception is also called if mode is FileMode.Open, and the file specified by path does not exist. The file must already exist in this mode.
IOException An I/O error occurs. For example, the exception is thrown if: path is not a valid path. That is, "c:\\Dir\myfile.txt" is missing an escape character in front of the backslash between Dir and myfile.txt.The directory path leading to the file specified by path does not exist on the system. That is, if Dir is not a directory on drive C, "c:\\Dir\\myfile.txt" will result in an error. mode is FileMode.CreateNew and the file specified by path already exists. The file must not already exist in this mode. access requested is not permitted by the operating system for the specified path. For example: access is read/write and there is an attempt to open the existing file "c:\\Dir\\myfile.txt", but the file or directory is set for read-only access.
SecurityException The caller does not have the appropriate FileIOPermission.

Requirements

NGWS Runtime Security:

FileIOPermissionAccess Write flag required by FileMode.Create or FileMode.CreateNew, by FileMode.OpenOrCreate when access is FileAccess.ReadWrite and the file does not exist, or when access is FileAccess.Read, and by FileMode.Truncate, FileAccess.Write, and FileAccess.ReadWrite.
FileIOPermissionAccess Read flag required by FileMode.Open, FileAccess.Read, and FileAccess.ReadWrite.
FileIOPermissionAccess Append flag required by FileMode.Create or FileMode.CreateNew, by FileMode.OpenOrCreate when access is FileAccess.ReadWrite and the file does not yet exist, and byFileMode.OpenOrCreate if the file does not yet exist.

See Also

FileStream Class | FileStream Members | System.IO Namespace | FileStream Constructor Overload List