Create File with File Options in C#

Create File with File Options in C#
  • 6207
Read this article to learn more about the File.Create method. 


Create File with File Options

The File.Create method takes third parameters as a FileOptions enumeration that can be used to specify advanced options for creating a FileStream object. 

FileStream fs = File.Create(fileName, 1024, FileOptions.WriteThrough);

The following values 
None – Default value. No additional options. 
WriteThrough – Indicates that the system should write through any intermediate cache and go directly to disk.
Asynchronous - Indicates that a file can be used for asynchronous reading and writing.
RandomAccess - Indicates that the file is accessed randomly. The system can use this as a hint to optimize file caching.
DeleteOnClose - Indicates that a file is automatically deleted when it is no longer in use.
SequentialScan - 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 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.
Encrypted - Indicates that a file is encrypted and can be decrypted only by using the same user account used for encryption.

© 2020 DotNetHeaven. All rights reserved.