← Interactive API Explorer
Namespace: System.IO

File

Provides static methods for the creation, copying, deletion, moving, and opening of a single file, and aids in the creation of FileStream objects.

Properties (4)

String Path
Gets or sets the path of the directory to watch.
Value: The path to monitor. The default is an empty string ("").
String Filter
Gets or sets the filter string used to determine what files are monitored in a directory.
Value: The filter string. The default is "*.*" (Watches all files.)
bool IncludeSubdirectories
Gets or sets a value indicating whether subdirectories within the specified path should be monitored.
Value: true if you want to monitor subdirectories; otherwise, false. The default is false.
bool EnableRaisingEvents
Gets or sets a value indicating whether the component is enabled.
Value: true if the component is enabled; otherwise, false. The default is false. If you are using the component on a designer in Visual Studio 2005, the default is true.

Methods (10)

bool Exists(String)
Determines whether the specified file exists.
ParameterDescription
pathThe file to check.
Returns: true if the caller has the required permissions and path contains the name of an existing file; otherwise, false. This method also returns false if path is null, an invalid path, or a zero-length string. If the caller does not have sufficient permissions to read the specified file, no exception is thrown and the method returns false regardless of the existence of path.
byte[] ReadAllBytes(String)
Opens a binary file, reads the contents of the file into a byte array, and then closes the file.
ParameterDescription
pathThe file to open for reading.
Returns: A byte array containing the contents of the file.
String ReadAllText(String)
Opens a text file, reads all the text in the file, and then closes the file.
ParameterDescription
pathThe file to open for reading.
Returns: A string containing all the text in the file.
void WriteAllBytes(String,Byte[])
Creates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is overwritten.
ParameterDescription
pathThe file to write to.
bytesThe bytes to write to the file.
void WriteAllText(String,String)
Creates a new file, writes the specified string to the file, and then closes the file. If the target file already exists, it is overwritten.
ParameterDescription
pathThe file to write to.
contentsThe string to write to the file.
FileStream Open(String,IO.FileMode)
Opens a FileStream on the specified path with read/write access with no sharing.
ParameterDescription
pathThe file to open.
modeA FileMode value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.
Returns: A FileStream opened in the specified mode and path, with read/write access and not shared.
FileStream OpenRead(String)
Opens an existing file for reading.
ParameterDescription
pathThe file to be opened for reading.
Returns: A read-only FileStream on the specified path.
FileStream OpenWrite(String)
Opens an existing file or creates a new file for writing.
ParameterDescription
pathThe file to be opened for writing.
Returns: An unshared FileStream object on the specified path with Write access.
File(String)Constructor
Initializes a new instance of the FileSystemWatcher class, given the specified directory to monitor.
ParameterDescription
pathThe directory to monitor, in standard or Universal Naming Convention (UNC) notation.
File(String,String)Constructor
Initializes a new instance of the FileSystemWatcher class, given the specified directory and type of files to monitor.
ParameterDescription
pathThe directory to monitor, in standard or Universal Naming Convention (UNC) notation.
filterThe type of files to watch. For example, "*.txt" watches for changes to all text files.