File Enum FileAccess Enum Fields Remarks Applies to See also FileAttributes Enum Fields Remarks Applies to See also FileMode Enum Fields Remarks Applies to See also FileOptions Enum Fields Remarks Applies to FileShare Enum Fields
Remarks Applies to See also Source/Reference
A FileAccess parameter is specified in many of the constructors for File, FileInfo, FileStream, and other constructors where it is important to control the kind of access users have to a file.
This file is marked to be included in incremental backup operation. Windows sets this attribute whenever the file is modified, and backup software should clear it when processing the file during incremental backup.
Compressed
2048
The file is compressed.
Device
64
Reserved for future use.
Directory
16
The file is a directory. Directory is supported on Windows, Linux, and macOS.
Encrypted
16384
The file or directory is encrypted. For a file, this means that all data in the file is encrypted. For a directory, this means that encryption is the default for newly created files and directories.
Hidden
2
The file is hidden, and thus is not included in an ordinary directory listing. Hidden is supported on Windows, Linux, and macOS.
IntegrityStream
32768
The file or directory includes data integrity support. When this value is applied to a file, all data streams in the file have integrity support. When this value is applied to a directory, all new files and subdirectories within that directory, by default, include integrity support.
Normal
128
The file is a standard file that has no special attributes. This attribute is valid only if it is used alone. Normal is supported on Windows, Linux, and macOS.
NoScrubData
131072
The file or directory is excluded from the data integrity scan. When this value is applied to a directory, by default, all new files and subdirectories within that directory are excluded from data integrity.
NotContentIndexed
8192
The file will not be indexed by the operating system's content indexing service.
Offline
4096
The file is offline. The data of the file is not immediately available.
ReadOnly
1
The file is read-only. ReadOnly is supported on Windows, Linux, and macOS. On Linux and macOS, changing the ReadOnly flag is a permissions operation.
ReparsePoint
1024
The file contains a reparse point, which is a block of user-defined data associated with a file or a directory. ReparsePoint is supported on Windows, Linux, and macOS.
SparseFile
512
The file is a sparse file. Sparse files are typically large files whose data consists of mostly zeros.
System
4
The file is a system file. That is, the file is part of the operating system or is used exclusively by the operating system.
Temporary
256
The file is temporary. A temporary file contains data that is needed while an application is executing but is not needed after the application is finished. File systems try to keep all the data in memory for quicker access rather than flushing the data back to mass storage. A temporary file should be deleted by the application as soon as it is no longer needed.
Remarks
You can get attributes for files and directories by calling the File.GetAttributes method, and you can set them by calling the File.SetAttributes method.
It is not possible to change the compression status of a File object by using the File.SetAttributes method. Instead, you must actually compress the file using either a compression tool or one of the classes in the System.IO.Compression namespace.
The following attributes are not supported by .NET Core on Linux and macOS:
On Unix systems, the value returned by File.GetAttributes includes Hidden for a file whose name begins with a period ("."). On macOS, you can get or set the hidden flag.
Opens the file if it exists and seeks to the end of the file, or creates a new file. This requires 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.
Create
2
Specifies that the operating system should create a new file. If the file already exists, it will be overwritten. This requires Write permission. FileMode.Create is equivalent to requesting that if the file does not exist, use CreateNew; otherwise, use Truncate. If the file already exists but is a hidden file, an
UnauthorizedAccessException exception is thrown.
CreateNew
1
Specifies that the operating system should create a new file. This requires Write permission. If the file already exists, an IOException exception is thrown.
Open
3
Specifies that the operating system should open an existing file. The ability to open the file is dependent on the value specified by the FileAccess enumeration. A FileNotFoundException exception is thrown if the file does not exist.
OpenOrCreate
4
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, Read permission is required. If the file access is FileAccess.Write, Write permission is required. If the file is opened with FileAccess.ReadWrite, both
Read and Write permissions are required.
Truncate
5
Specifies that the operating system should open an existing file. When the file is opened, it should be truncated so that its size is zero bytes. This requires Write permission. Attempts to read from a file opened with FileMode.Truncate cause an ArgumentException exception.
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.
Indicates that a file can be used for asynchronous reading and writing.
DeleteOnClose
67108864
Indicates that a file is automatically deleted when it is no longer in use.
Encrypted
16384
Indicates that a file is encrypted and can be decrypted only by using the same user account used for encryption.
None
0
Indicates that no additional options should be used when creating a FileStream object.
RandomAccess
268435456
Indicates that the file is accessed randomly. The system can use this as a hint to optimize file caching.
SequentialScan
134217728
Indicates that the file is to be accessed sequentially from beginning to end. The system can use this as a hint to optimize file caching. If an application moves the file pointer for random access, optimum caching may not occur; however, correct operation is still guaranteed. Specifying this flag can increase performance in some cases.
WriteThrough
-2147483648
Indicates that the system should write through any intermediate cache and go directly to disk.
Remarks
Specifying the FileOptions.SequentialScan flag can increase performance for applications that read large files using sequential access. Performance gains can be even more noticeable for applications that read large files mostly sequentially, but occasionally skip over small ranges of bytes.
Makes the file handle inheritable by child processes. This is not directly supported by Win32.
None
0
Declines sharing of the current file. Any request to open the file (by this process or another process) will fail until the file is closed.
Read
1
Allows subsequent opening of the file for reading. If this flag is not specified, any request to open the file for reading (by this process or another process) will fail until the file is closed. However, even if this flag is specified, additional permissions might still be needed to access the file.
ReadWrite
3
Allows subsequent opening of the file for reading or writing. If this flag is not specified, any request to open the file for reading or writing (by this process or another process) will fail until the file is closed. However, even if this flag is specified, additional permissions might still be needed to access the file.
Write
2
Allows subsequent opening of the file for writing. If this flag is not specified, any request to open the file for writing (by this process or another process) will fail until the file is closed. However, even if this flag is specified, additional permissions might still be needed to access the file.
A typical use of this enumeration is to define whether two processes can simultaneously read from the same file. For example, if a file is opened and Read is specified, other users can open the file for reading but not for writing.