FileOptions Enum

Definition

Represents advanced options for creating a FileStream object.

This enumeration supports a bitwise combination of its member values.

public enum class FileOptions
[System.Flags]
public enum FileOptions
[System.Flags]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum FileOptions
[<System.Flags>]
type FileOptions = 
[<System.Flags>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type FileOptions = 
Public Enum FileOptions
Inheritance
FileOptions
Attributes

Fields

Asynchronous 1073741824

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.

Examples

The following example shows how to use the Asynchronous value when creating a file stream.

using System;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            WriteToFile();
        }

        static async void WriteToFile()
        {
            byte[] bytesToWrite = Encoding.Unicode.GetBytes("example text to write");
            using (FileStream createdFile = File.Create("c:/Temp/testfile.txt", 4096, FileOptions.Asynchronous))
            {
                await createdFile.WriteAsync(bytesToWrite, 0, bytesToWrite.Length);
            }
        }
    }
}
Imports System.IO
Imports System.Text

Module Module1

    Sub Main()
        WriteToFile()
    End Sub

    Async Sub WriteToFile()
        Dim bytesToWrite = Encoding.Unicode.GetBytes("example text to write")
        Using createdFile As FileStream = File.Create("c:/Temp/testfile.txt", 4096, FileOptions.Asynchronous)
            Await createdFile.WriteAsync(bytesToWrite, 0, bytesToWrite.Length)
        End Using
    End Sub

End Module

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.

Applies to