Specifies how the operating system should open a file. These values, which are used by the FileStream constructors, control whether a file is overwritten or opened, or some combination thereof.
[Visual Basic] Public Enum FileMode [C#] public enum FileMode [C++] public enum FileMode
[JScript] In JScript, you can use the enumerations in the NGWS frameworks, but you cannot define your own.
To append to a file, use Append. To truncate a file or create it if it does not exist, use Create.
Member Name | Description |
---|---|
Append | Opens the file if it exists and seeks to the end of the file, or creates a new file. FileMode.Append can only be used in conjunction with FileAccess.Write. If FileAccess.ReadWrite is specified and FileMode.Append is also specified, an ArgumentException is thrown. |
Create | Specifies that the operating system should create a new file. If the file already exists, it will be overwritten. The Append and Write flags of FileIOPermissionAccess are required. |
CreateNew | Specifies that the operating system should create a new file. Specifies that the operating system should create a new file. The Append and Write flags of FileIOPermissionAccess are required. |
Open | Specifies that the operating system should open an existing file. The Read flag of FileIOPermissionAccess is required. |
OpenOrCreate | Specifies that the operating system should open a file if it exists; otherwise, a new file should be created. If the file is opened with FileAccess.Read, the Read flag of FileIOPermissionAccess is required. If file access is FileAccess.ReadWrite and the file exists, the Write flag of FileIOPermissionAccess is required; if it doesn't exist, the Append flag of FileIOPermissionAccess is required in addition. |
Truncate | Specifies that the operating system should open an existing file. Once opened, the file should be truncated so that its size is zero bytes. The file must be opened with at least the Write flag of FileIOPermissionAccess enabled. |
Namespace: System.IO
Assembly: mscorlib.dll