Export (0) Print
Expand All
2 out of 2 rated this helpful - Rate this topic

FileAccess Enumeration

Defines constants for read, write, or read/write access to a file.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

[Visual Basic]
<Flags>
<Serializable>
Public Enum FileAccess
[C#]
[Flags]
[Serializable]
public enum FileAccess
[C++]
[Flags]
[Serializable]
__value public enum FileAccess
[JScript]
public
   Flags
 Serializable
enum FileAccess

Remarks

For an example of creating a file and writing text to a file, see Writing Text to a File. For an example of reading text from a file, see Reading Text from a File. For an example of reading from and writing to a binary file, see Reading and Writing to a Newly Created Data File.

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.

Members

Member name Description Value
Read

Supported by the .NET Compact Framework.

Read access to the file. Data can be read from the file. Combine with Write for read/write access. 1
ReadWrite

Supported by the .NET Compact Framework.

Read and write access to the file. Data can be written to and read from the file. 3
Write

Supported by the .NET Compact Framework.

Write access to the file. Data can be written to the file. Combine with Read for read/write access. 2

Example

The following FileStream constructor grants read-only access to an existing file (FileAccess.Read).

[Visual Basic] 
Dim s2 As New FileStream(name, FileMode.Open, FileAccess.Read, FileShare.Read)

[C#] 
FileStream s2 = new FileStream(name, FileMode.Open, FileAccess.Read, FileShare.Read);

[C++] 
FileStream* s2 = new FileStream(name, FileMode::Open, FileAccess::Read, FileShare::Read);

[JScript] 
var s2 : FileStream = new FileStream(name, FileMode.Open, FileAccess.Read, FileShare.Read);

Requirements

Namespace: System.IO

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: Mscorlib (in Mscorlib.dll)

See Also

System.IO Namespace | File | FileInfo | FileStream | IsolatedStorageFileStream | Working with I/O | Reading Text from a File | Writing Text to a File | Basic File I/O | Reading and Writing to a Newly Created Data File

Show:
© 2014 Microsoft. All rights reserved.