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, Boolean)

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, _
   ByVal useAsync As Boolean _
)
[C#]
public FileStream(
   string path,
   FileMode mode,
   FileAccess access,
   FileShare share,
   int bufferSize,
   bool useAsync
);
[C++]
public: FileStream(
   String* path,
   FileMode mode,
   FileAccess access,
   FileShare share,
   int bufferSize,
   bool useAsync
);
[JScript]
public function FileStream(
   path : String,
   mode : FileMode,
   access : FileAccess,
   share : FileShare,
   bufferSize : int,
   useAsync : Boolean
);

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.
useAsync
Specifies whether to use asynchronous I/O or synchronous IO. When opened asynchronously, the BeginRead and BeginWrite methods will perform better on large reads or writes, but they may be much slower for small reads or writes. If you have designed your application to take advantage of asynchronous IO, set this to true. Using async IO correctly can speed up applications by as much as a factor of 10, but using it without redesigning the application for asynchronous IO can decrease performance by as much as a factor of 10.

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 Required by FileMode.Create or FileMode.CreateNew.

Required by FileMode.OpenOrCreate when access is FileAccess.ReadWrite and the file does not exist, or when access is FileAccess.Read.

Required by FileMode.Truncate.

Required by FileAccess.Write.

Required by FileAccess.ReadWrite.

FileIOPermissionAccess.Read Required by FileMode.Open.

Required by FileAccess.Read.

Required by FileAccess.ReadWrite.

FileIOPermissionAccess.Append Required by FileMode.Create or FileMode.CreateNew.

Required by FileMode.OpenOrCreate when access is FileAccess.ReadWrite and the file does not yet exist.

Required by FileMode.OpenOrCreate if the file does not yet exist.

System.Security.Permissions.FileIOPermissionAccess.Append and System.Security.Permissions.FileIOPermissionAccess.Write Required by FileMode.Create or FileMode.CreateNew.

Required by FileMode.OpenOrCreate when access is FileAccess.ReadWrite and the file does not yet exist.

Required by FileMode.OpenOrCreate if the file does not yet exist.

FileIOPermissionAccess.Read Required by FileMode.Open.

Required by FileAccess.Read.

FileIOPermissionAccess.Write Required by FileMode.OpenOrCreate if access is FileAccess.Read.

Required by FileMode.OpenOrCreate when access is FileAccess.ReadWrite and the file already exists.

Required by FileMode.Truncate.

Required by FileAccess.Write.

System.Security.Permissions.FileIOPermissionAccess.Read and System.Security.Permissions.FileIOPermissionAccess.Write Required by FileAccess.ReadWrite.

See Also

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