Specifies how the operating system should open a file.
Assembly: mscorlib (in mscorlib.dll)
Opens the file if it exists and seeks to the end of the file, or creates a new file. This requires FileIOPermissionAccess::Append permission. FileMode.Append can be used only in conjunction with FileAccess.Write. Trying to seek to a position before the end of the file throws an IOException exception, and any attempt to read fails and throws a NotSupportedException exception.
Specifies that the operating system should create a new file. If the file already exists, it will be overwritten. This requires FileIOPermissionAccess::Write permission. FileMode.Create is equivalent to requesting that if the file does not exist, use ; otherwise, use . If the file already exists but is a hidden file, an UnauthorizedAccessException exception is thrown.
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, FileIOPermissionAccess::Read permission is required. If the file access is FileAccess.Write, FileIOPermissionAccess::Write permission is required. If the file is opened with FileAccess.ReadWrite, both FileIOPermissionAccess::Read and FileIOPermissionAccess::Write permissions are required.
For an example of creating a file and writing text to a file, see How to: Write Text to a File. For an example of reading text from a file, see How to: Read Text from a File. For an example of reading from and writing to a binary file, see How to: Read and Write to a Newly Created Data File.
FileMode parameters control whether a file is overwritten, created, opened, or some combination thereof. Use Open to open an existing file. To append to a file, use Append. To truncate a file or create a file if it doesn't exist, use Create.
Available since 10
Available since 1.1
Available since 2.0
Windows Phone Silverlight
Available since 7.0