Click or drag to resize
FileInfoOpen Method (FileMode, FileAccess)
Opens a file in the specified mode with read, write, or read/write access.

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll) Version: 4.0.0.0
Syntax
C#
public FileStream Open(
	FileMode mode,
	FileAccess access
)

Parameters

mode
Type: System.IOFileMode
A FileMode constant specifying the mode (for example, Open or Append) in which to open the file.
access
Type: System.IOFileAccess
A FileAccess constant specifying whether to open the file with Read, Write, or ReadWrite file access.

Return Value

Type: FileStream
A FileStream object opened in the specified mode and access, and unshared.
Exceptions
ExceptionCondition
SecurityExceptionThe caller does not have the required permission.
ArgumentExceptionpath is empty or contains only white spaces.
FileNotFoundExceptionThe file is not found.
ArgumentNullExceptionOne or more arguments is null.
UnauthorizedAccessExceptionpath is read-only or is a directory.
DirectoryNotFoundExceptionThe specified path is invalid, such as being on an unmapped drive.
IOExceptionThe file is already open.
See Also