This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
'Declaration <SerializableAttribute> _ <ComVisibleAttribute(True)> _ <FlagsAttribute> _ Public Enumeration FileOptions 'Usage Dim instance As FileOptions
/** @attribute SerializableAttribute() */ /** @attribute ComVisibleAttribute(true) */ /** @attribute FlagsAttribute() */ public enum FileOptions
|Asynchronous||Indicates that a file can be used for asynchronous reading and writing.|
|DeleteOnClose||Indicates that a file is automatically deleted when it is no longer in use.|
|Encrypted||Indicates that a file is encrypted and can be decrypted only by using the same user account used for encryption.|
|None||Indicates no additional parameters.|
|RandomAccess||Indicates that the file is accessed randomly. The system can use this as a hint to optimize file caching.|
|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.
|WriteThrough||Indicates that the system should write through any intermediate cache and go directly to disk.|
The following code example writes data to a file and then reads the data using the FileStream object.
Imports System Imports System.IO Imports System.Text Imports System.Security.AccessControl Module FileStreamExample Sub Main() Try ' Create a file and write data to it. ' Create an array of bytes. Dim messageByte As Byte() = Encoding.ASCII.GetBytes("Here is some data.") ' Specify an access control list (ACL) Dim fs As New FileSecurity() fs.AddAccessRule(New FileSystemAccessRule("DOMAINNAME\AccountName", FileSystemRights.ReadData, AccessControlType.Allow)) ' Create a file using the FileStream class. Dim fWrite As New FileStream("test.txt", FileMode.Create, FileSystemRights.Modify, FileShare.None, 8, FileOptions.None, fs) ' Write the number of bytes to the file. fWrite.WriteByte(System.Convert.ToByte(messageByte.Length)) ' Write the bytes to the file. fWrite.Write(messageByte, 0, messageByte.Length) ' Close the stream. fWrite.Close() ' Open a file and read the number of bytes. Dim fRead As New FileStream("test.txt", FileMode.Open) ' The first byte is the string length. Dim length As Integer = Fix(fRead.ReadByte()) ' Create a new byte array for the data. Dim readBytes(length) As Byte ' Read the data from the file. fRead.Read(readBytes, 0, readBytes.Length) ' Close the stream. fRead.Close() ' Display the data. Console.WriteLine(Encoding.ASCII.GetString(readBytes)) Console.WriteLine("Done writing and reading data.") Catch e As Exception Console.WriteLine(e) End Try Console.ReadLine() End Sub End Module
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter EditionThe Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.