BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.Object System.Runtime.InteropServices.ComVisible(true)

Use the class for typical operations such as copying, moving, renaming, creating, opening, deleting, and appending to files. You can also use the class to get and set file attributes or information related to the creation, access, and writing of a file.

Many of the methods return other I/O types when you create or open files. You can use these other types to further manipulate a file. For more information, see specific members such as , , or .

Because all methods are static, it might be more efficient to use a method rather than a corresponding instance method if you want to perform only one action. All methods require the path to the file that you are manipulating.

The static methods of the class perform security checks on all methods. If you are going to reuse an object several times, consider using the corresponding instance method of instead, because the security check will not always be necessary.

By default, full read/write access to new files is granted to all users.

The following table describes the enumerations that are used to customize the behavior of various methods.

Enumeration

Description

Specifies read and write access to a file.

Specifies the level of access permitted for a file that is already in use.

Specifies whether the contents of an existing file are preserved or overwritten, and whether requests to create an existing file cause an exception.

In members that accept a path as an input string, that path must be well-formed or an exception is raised. For example, if a path is fully qualified but begins with a space, the path is not trimmed in methods of the class. Therefore, the path is malformed and an exception is raised. Similarly, a path or a combination of paths cannot be fully qualified twice. For example, "c:\temp c:\windows" also raises an exception in most cases. Ensure that your paths are well-formed when using methods that accept a path string.

In members that accept a path, the path can refer to a file or just a directory. The specified path can also refer to a relative path or a Universal Naming Convention (UNC) path for a server and share name. For example, all the following are acceptable paths:

"c:\\MyDir\\MyFile.txt" in C#, or "c:\MyDir\MyFile.txt" in Visual Basic.

"c:\\MyDir" in C#, or "c:\MyDir" in Visual Basic.

"MyDir\\MySubdir" in C#, or "MyDir\MySubDir" in Visual Basic.

"\\\\MyServer\\MyShare" in C#, or "\\MyServer\MyShare" in Visual Basic.

For a list of common I/O tasks, see Common I/O Tasks.

Provides static methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of objects.

- Method
  4.0.0.0
  System.Void `` ``

  The method creates the file if it doesn’t exist, but it doesn't create new directories. Therefore, the value of the parameter must contain existing directories.

  Appends lines to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file.

  The file to append the lines to. The file is created if it doesn't already exist. The lines to append to the file.
- Method
  4.0.0.0
  System.Void `` `` ``

  The method creates the file if it doesn’t exist, but it doesn't create new directories. Therefore, the value of the parameter must contain existing directories.

  You can use this method to create a file that contains the following:

  The results of a LINQ to Objects query on the lines of a file, as obtained by using the method.

  The contents of a collection that implements an of strings.

  Appends lines to a file by using a specified encoding, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file.

  The file to append the lines to. The file is created if it doesn't already exist. The lines to append to the file. The character encoding to use.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  Given a string and a file path, this method opens the specified file, appends the string to the end of the file, and then closes the file. The file handle is guaranteed to be closed by this method, even if exceptions are raised.

  The method creates the file if it doesn’t exist, but it doesn't create new directories. Therefore, the value of the parameter must contain existing directories.

  Opens a file, appends the specified string to the file, and then closes the file. If the file does not exist, this method creates a file, writes the specified string to the file, then closes the file.

  The file to append the specified string to. The string to append to the file.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` `` ``

  Given a string and a file path, this method opens the specified file, appends the string to the end of the file using the specified encoding, and then closes the file. The file handle is guaranteed to be closed by this method, even if exceptions are raised.

  The method creates the file if it doesn’t exist, but it doesn't create new directories. Therefore, the value of the parameter must contain existing directories.

  Appends the specified string to the file, creating the file if it does not already exist.

  The file to append the specified string to. The string to append to the file. The character encoding to use.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IO.StreamWriter `` The caller does not have the required permission. is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters. was not found. is . The directory information specified in was not found. The length of or the absolute path information for exceeds the implementation-specific maximum length. Requires permission to write to the specified file. See . A general I/O exception occurred, such as trying to access a CD-ROM drive whose tray is open. is in an implementation-specific invalid format. Access is denied. The caller does not have the required permission.

  This method is equivalent to the constructor overload. If the file specified by does not exist, it is created. If the file does exist, write operations to the append text to the file. Additional threads are permitted to read the file while it is open.

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  The parameter is not case-sensitive.

  For a list of common I/O tasks, see Common I/O Tasks.

  Creates a that appends UTF-8 encoded text to an existing file, or to a new file if the specified file does not exist.

  A stream writer that appends UTF-8 encoded text to the specified file or to a new file.

  The path to the file to append to. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  exists.

  -or-

  An I/O error occurred.

  or is .

  or is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters.

  -or-

  or specifies a directory.

  The caller does not have the required permission. Directory information in or was not found. was not found. The length or the absolute path information for or exceeds the system-defined maximum length. Requires permission to read the source file and write the destination file. See and . The caller does not have the required permission.

  This method is equivalent to the method overload with the parameter set to false.

  The and parameters can specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see the method. This method does not support wildcard characters in the parameters.

  The attributes of the original file are retained in the copied file.

  Copies an existing file to a new file. Overwriting a file of the same name is not allowed.

  The file to copy. The name of the destination file. This cannot be a directory or an existing file. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` `` ``

  is read-only (write-protected), or exists and is .

  -or-

  An I/O error occurred.

  or is .

  or is a zero-length string, contains only white space, or contains one or more invalid characters.

  -or-

  or specifies a directory.

  The caller does not have the required permission. Directory information in or was not found. was not found. The length or the absolute path information for or exceeds the system-defined maximum length. Requires permission to read the source file and write the destination file. See and . The caller does not have the required permission.

  The and parameters can specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. This method does not support wildcard characters in the parameters.

  The attributes of the original file are retained in the copied file.

  For a list of common I/O tasks, see Common I/O Tasks.

  Copies an existing file to a new file. Overwriting a file of the same name is allowed.

  The file to copy. The name of the destination file. This cannot be a directory. true if the destination file can be overwritten; otherwise, false. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IO.FileStream `` The caller does not have the required permission.

  is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters.

  is . The directory information specified in was not found. An I/O error occurred while creating the file. The caller does not have the required permission. The length of or the absolute path information for exceeds the system-defined maximum length. Requires permission to write the specified file. See .

  The object created by this method has a default value of ; no other process or code can access the created file until the original file handle is closed.

  This method is equivalent to the method overload using the default buffer size.

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  If the specified file does not exist, it is created; if it does exist and it is not read-only, the contents are overwritten.

  By default, full read/write access to new files is granted to all users. The file is opened with read/write access and must be closed before it can be opened by another application.

  For a list of common I/O tasks, see Common I/O Tasks.

  Creates or overwrites a file in the specified path.

  A that provides read/write access to the file specified in .

  The path and name of the file to create. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IO.FileStream `` `` The caller does not have the required permission.

  is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters.

  is . The directory information specified in was not found. An I/O error occurred while creating the file. The caller does not have the required permission. The length of or the absolute path information for exceeds the system-defined maximum length. Requires permission to write the specified file. See .

  The object created by this method has a default value of ; no other process or code can access the created file until the original file handle is closed.

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  This method is equivalent to the constructor overload. If the specified file does not exist, it is created; if it does exist and it is not read-only, the contents are overwritten.

  By default, full read/write access to new files is granted to all users. The file is opened with read/write access and must be closed before it can be opened by another application.

  For a list of common I/O tasks, see Common I/O Tasks.

  Creates or overwrites the specified file.

  A with the specified buffer size that provides read/write access to the file specified in .

  The name of the file. The number of bytes buffered for reads and writes to the file. 0
- Method
  2.0.0.0
  4.0.0.0
  System.IO.FileStream `` `` ``

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  This method is equivalent to the constructor overload. If the specified file does not exist, it is created; if it does exist and it is not read-only, the contents are overwritten.

  By default, full read/write access to new files is granted to all users. The file is opened with read/write access and must be closed before it can be opened by another application.

  For a list of common I/O tasks, see Common I/O Tasks.

  Creates or overwrites the specified file, specifying a buffer size and a value that describes how to create or overwrite the file.

  A new file with the specified buffer size.

  The name of the file. The number of bytes buffered for reads and writes to the file. One of the values that describes how to create or overwrite the file.
- Method
  2.0.0.0
  4.0.0.0
  System.IO.FileStream `` `` `` ``

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  This method is equivalent to the constructor overload. If the specified file does not exist, it is created; if it does exist and it is not read-only, the contents are overwritten.

  By default, full read/write access to new files is granted to all users. The file is opened with read/write access and must be closed before it can be opened by another application.

  For a list of common I/O tasks, see Common I/O Tasks.

  Creates or overwrites the specified file with the specified buffer size, file options, and file security.

  A new file with the specified buffer size, file options, and file security.

  The name of the file. The number of bytes buffered for reads and writes to the file. One of the values that describes how to create or overwrite the file. One of the values that determines the access control and audit security for the file.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IO.StreamWriter `` The caller does not have the required permission. is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters. is . The directory information specified in was not found. The length of or the absolute path information for exceeds the implementation-specific maximum length. Requires permission to write the specified file. See . A general I/O exception occurred, such as trying to access a CD-ROM drive whose tray is open. is in an implementation-specific invalid format. Access is denied. The caller does not have the required permission.

  This method is equivalent to the constructor overload with the parameter set to false. If the file specified by does not exist, it is created. If the file does exist, its contents are overwritten. Additional threads are permitted to read the file while it is open.

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  For a list of common I/O tasks, see Common I/O Tasks.

  Creates or opens a file for writing UTF-8 encoded text.

  A that writes to the specified file using UTF-8 encoding.

  The file to be opened for writing. 0
- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  The method allows you to decrypt a file that was encrypted using the method. The method can decrypt only files that were encrypted using the current user account.

  The method requires exclusive access to the file being decrypted, and will raise an exception if another process is using the file. If the file is not encrypted, will return a nonzero value, which indicates success.

  Both the method and the method use the cryptographic service provider (CSP) installed on the computer and the file encryption keys of the process calling the method.

  The current file system must be formatted as NTFS and the current operating system must be Windows NT or later.

  Decrypts a file that was encrypted by the current account using the method.

  A path that describes a file to decrypt.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters. is . The directory information specified in was not found. The specified file is in use. The caller does not have the required permission. The caller does not have the required permission. The length of or the absolute path information for exceeds the system-defined maximum length. Requires permission to write to the specified file. See .

  Specify a file name with any relative or absolute path information for the parameter. Wildcard characters cannot be included. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  If the file to be deleted does not exist, no exception is thrown.

  For a list of common I/O tasks, see Common I/O Tasks.

  Deletes the specified file.

  The name of the file to be deleted. Wildcard characters are not supported. 0
- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  The method allows you to encrypt a file so that only the account used to call this method can decrypt it. Use the method to decrypt a file encrypted by the method.

  The method requires exclusive access to the file being encrypted, and will fail if another process is using the file.

  Both the method and the method use the cryptographic service provider (CSP) installed on the computer and the file encryption keys of the process calling the method.

  The current file system must be formatted as NTFS and the current operating system must be Windows NT or later.

  Encrypts a file so that only the account used to encrypt the file can decrypt it.

  A path that describes a file to encrypt.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean `` Requires permission to read the specified file. See .

  The method should not be used for path validation, this method merely checks if the file specified in exists. Passing an invalid path to returns false. To check whether the path contains any invalid characters, you can call the method to retrieve the characters that are invalid for the file system. You can also create a regular expression to test the whether the path is valid for your environment. For examples of acceptable paths, see .

  Be aware that another process can potentially do something with the file in between the time you call the method and perform another operation on the file, such as .

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  If describes a directory, this method returns false. Trailing spaces are removed from the parameter before determining if the file exists.

  The method returns false if any error occurs while trying to determine if the specified file exists. This can occur in situations that raise exceptions such as passing a file name with invalid characters or too many characters, a failing or missing disk, or if the caller does not have permission to read the file.

  Determines whether the specified file exists.

  true if the caller has the required permissions and contains the name of an existing file; otherwise, false. This method also returns false if 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 .

  The file to check. 0
- Method
  2.0.0.0
  4.0.0.0
  System.Security.AccessControl.FileSecurity ``

  Use the method to retrieve the access control list (ACL) entries for a file.

  An ACL describes individuals and/or groups who have, or do not have, rights to specific actions on the given file. For more information, see ACL Technology Overview and How to: Add or Remove an Access Control List Entry.

  In NTFS environments, and are granted to the user if the user has rights on the parent folder. To deny and , deny on the parent directory.

  Gets a object that encapsulates the access control list (ACL) entries for a specified file.

  A object that encapsulates the access control rules for the file described by the parameter.

  The path to a file containing a object that describes the file's access control list (ACL) information.
- Method
  2.0.0.0
  4.0.0.0
  System.Security.AccessControl.FileSecurity `` ``

  Use the method to retrieve the access control list (ACL) entries for a file.

  An ACL describes individuals and/or groups who have, or do not have, rights to specific actions on the given file. For more information, see ACL Technology Overview and How to: Add or Remove an Access Control List Entry.

  In NTFS environments, and are granted to the user if the user has rights on the parent folder. To deny and , deny on the parent directory.

  Gets a object that encapsulates the specified type of access control list (ACL) entries for a particular file.

  A object that encapsulates the access control rules for the file described by the parameter.

  The path to a file containing a object that describes the file's access control list (ACL) information. One of the values that specifies the type of access control list (ACL) information to receive.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IO.FileAttributes ``

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  For a list of common I/O tasks, see Common I/O Tasks.

  Gets the of the file on the path.

  The of the file on the path.

  The path to the file.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.DateTime `` is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters. is . was not found. The length of or the absolute path information for exceeds the system-defined maximum length. The caller does not have the required permission. Requires permission to read the specified file or directory. See . The caller does not have the required permission.

  This method may return an inaccurate value, because it uses native functions whose values may not be continuously updated by the operating system.

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  If the file described in the parameter does not exist, this method returns 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC), adjusted to local time.

  NTFS-formatted drives may cache information about a file, such as file creation time, for a short period of time. As a result, it may be necessary to explicitly set the creation time of a file if you are overwriting or replacing an existing file.

  For a list of common I/O tasks, see Common I/O Tasks.

  Returns the creation date and time of the specified file or directory.

  A structure set to the creation date and time for the specified file or directory. This value is expressed in local time.

  The file or directory for which to obtain creation date and time information. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.DateTime ``

  This method may return an inaccurate value, because it uses native functions whose values may not be continuously updated by the operating system.

  If the file described in the parameter does not exist, this method returns 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC).

  NTFS-formatted drives may cache information about a file, such as file creation time, for a short period of time. As a result, it may be necessary to explicitly set the creation time of a file if you are overwriting or replacing an existing file.

  For a list of common I/O tasks, see Common I/O Tasks.

  Returns the creation date and time, in coordinated universal time (UTC), of the specified file or directory.

  A structure set to the creation date and time for the specified file or directory. This value is expressed in UTC time.

  The file or directory for which to obtain creation date and time information.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.DateTime `` is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters. is . was not found. The length of or the absolute path information for exceeds the system-defined maximum length. The caller does not have the required permission. Requires permission to read the specified file or directory. See . The caller does not have the required permission.

  This method may return an inaccurate value, because it uses native functions whose values may not be continuously updated by the operating system.

  If the file described in the parameter does not exist, this method returns 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC), adjusted to local time.

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  For a list of common I/O tasks, see Common I/O Tasks.

  Returns the date and time the specified file or directory was last accessed.

  A structure set to the date and time that the specified file or directory was last accessed. This value is expressed in local time.

  The file or directory for which to obtain access date and time information. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.DateTime ``

  This method may return an inaccurate value, because it uses native functions whose values may not be continuously updated by the operating system.

  If the file described in the parameter does not exist, this method returns 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC).

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  For a list of common I/O tasks, see Common I/O Tasks.

  Returns the date and time, in coordinated universal time (UTC), that the specified file or directory was last accessed.

  A structure set to the date and time that the specified file or directory was last accessed. This value is expressed in UTC time.

  The file or directory for which to obtain access date and time information.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.DateTime `` is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters. is . was not found. The length of or the absolute path information for exceeds the system-defined maximum length. The caller does not have the required permission. Requires permission to read the specified file or directory. See . The caller does not have the required permission.

  This method may return an inaccurate value, because it uses native functions whose values may not be continuously updated by the operating system. Each operating system manages the last write time according to its own rules. To improve performance, an operating system might not set the last write time value to the exact time of the last write operation, but might set it to a close approximation instead.

  If the file described in the parameter does not exist, this method returns 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC), adjusted to local time.

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  For a list of common I/O tasks, see Common I/O Tasks.

  Returns the date and time the specified file or directory was last written to.

  A structure set to the date and time that the specified file or directory was last written to. This value is expressed in local time.

  The file or directory for which to obtain write date and time information. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.DateTime ``

  This method may return an inaccurate value, because it uses native functions whose values may not be continuously updated by the operating system. Each operating system manages the last write time according to its own rules. To improve performance, an operating system might not set the last write time value to the exact time of the last write operation, but might set it to a close approximation instead.

  If the file described in the parameter does not exist, this method returns 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC).

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  For a list of common I/O tasks, see Common I/O Tasks.

  Returns the date and time, in coordinated universal time (UTC), that the specified file or directory was last written to.

  A structure set to the date and time that the specified file or directory was last written to. This value is expressed in UTC time.

  The file or directory for which to obtain write date and time information.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` `` already exists or is a directory. or is .

  or is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters.

  The caller does not have the required permission. The directory information in or was not found. was not found or specifies a directory. The length or absolute path information for or exceeds the system-defined maximum length. Requires permission to read from and write to and . See and . The caller does not have the required permission.

  This method works across disk volumes, and it does not throw an exception if the source and destination are the same. Note that if you attempt to replace a file by moving a file of the same name into that directory, you get an . You cannot use the Move method to overwrite an existing file.

  The and arguments are permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  If you try to move a file across disk volumes and that file is in use, the file is copied to the destination, but it is not deleted from the source.

  For a list of common I/O tasks, see Common I/O Tasks.

  Moves a specified file to a new location, providing the option to specify a new file name.

  The name of the file to move. The new path for the file. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IO.FileStream `` `` The caller does not have the required permission.

  is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters.

  was not found. is . specified an invalid value. The directory information specified in was not found. An I/O error occurred while opening the file. The caller does not have the required permission. The length of or the absolute path information for exceeds the system-defined maximum length. Requires permission to read and write the file. See and . A 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.

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  For a list of common I/O tasks, see Common I/O Tasks.

  Opens a on the specified path with read/write access.

  A opened in the specified mode and path, with read/write access and not shared.

  The file to open. A 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. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IO.FileStream `` `` `` The caller does not have the required permission.

  is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters.

  -or-

  specified and specified , , or .

  is or , but the specified file was not found. If a different mode is specified and the file was not found, a new one is created. is . or specified an invalid value. The directory information specified in was not found. An I/O error occurred, such as specifying when the file specified by path already exists. specified a read-only file and is not , or specified a directory. The length of or the absolute path information for exceeds the system-defined maximum length. Requires permission to read and might also require permission to write to the file. See and . A 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. A value that specifies the operations that can be performed on the file.

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  Opens a on the specified path, with the specified mode and access.

  An unshared that provides access to the specified file, with the specified mode and access.

  The file to open. A 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. A value that specifies the operations that can be performed on the file. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IO.FileStream `` `` `` `` The caller does not have the required permission.

  is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters.

  -or-

  specified and specified , , or .

  was not found. is . , , or specified an invalid value. The directory information specified in was not found. An I/O error occurred while opening the file. The caller does not have the required permission. The length of or the absolute path information for exceeds the system-defined maximum length. Requires permission to read and might also require permission to write the file. See and . A 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. A value that specifies the operations that can be performed on the file. A value specifying the type of access other threads have to the file.

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  For a list of common I/O tasks, see Common I/O Tasks.

  Opens a on the specified path, having the specified mode with read, write, or read/write access and the specified sharing option.

  A on the specified path, having the specified mode with read, write, or read/write access and the specified sharing option.

  The file to open. A 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. A value that specifies the operations that can be performed on the file. A value specifying the type of access other threads have to the file. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IO.FileStream `` The caller does not have the required permission. is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters. was not found. is . The directory information specified in was not found. The caller does not have the required permission. The length of or the absolute path information for exceeds the system-defined maximum length. Requires permission to read the specified file. See .

  This method is equivalent to the constructor overload with a value of , a value of and a value of .

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  For a list of common I/O tasks, see Common I/O Tasks.

  Opens an existing file for reading.

  A read-only on the specified path.

  The file to be opened for reading. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IO.StreamReader `` The caller does not have the required permission. is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters. was not found. is . The directory information specified in was not found. The length of or the absolute path information for exceeds the system-defined maximum length. Requires permission to write to the specified file. See . The caller does not have the required permission.

  This method is equivalent to the constructor overload.

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  For a list of common I/O tasks, see Common I/O Tasks.

  Opens an existing UTF-8 encoded text file for reading.

  A on the specified path.

  The file to be opened for reading. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.IO.FileStream `` The caller does not have the required permission. is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters. was not found. is . The directory information specified in was not found. The caller does not have the required permission. The length of or the absolute path information for exceeds the system-defined maximum length. Requires permission to write the specified file. See .

  This method is equivalent to the constructor overload with file mode set to , the access set to , and the share mode set to .

  The method opens a file if one already exists for the file path, or creates a new file if one does not exist. For an existing file, it does not append the new text to the existing text. Instead, it overwrites the existing characters with the new characters. If you overwrite a longer string (such as “This is a test of the OpenWrite method”) with a shorter string (such as “Second run”), the file will contain a mix of the strings (“Second runtest of the OpenWrite method”).

  The parameter may specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, use the method.

  For a list of common I/O tasks, see Common I/O Tasks.

  Opens an existing file or creates a new file for writing.

  An unshared object on the specified path with access.

  The file to be opened for writing. 0
- Method
  2.0.0.0
  4.0.0.0
  System.Byte[] ``

  Given a file path, this method opens the file, reads the contents of the file into a byte array, and then closes the file.

  Opens a binary file, reads the contents of the file into a byte array, and then closes the file.

  A byte array containing the contents of the file.

  The file to open for reading.
- Method
  2.0.0.0
  4.0.0.0
  System.String[] ``

  This method opens a file, reads each line of the file, then adds each line as an element of a string array. It then closes the file. A line is defined as a sequence of characters followed by a carriage return ('\r'), a line feed ('\n'), or a carriage return immediately followed by a line feed. The resulting string does not contain the terminating carriage return and/or line feed.

  This method attempts to automatically detect the encoding of a file based on the presence of byte order marks. Encoding formats UTF-8 and UTF-32 (both big-endian and little-endian) can be detected.

  Opens a text file, reads all lines of the file, and then closes the file.

  A string array containing all lines of the file.

  The file to open for reading.
- Method
  2.0.0.0
  4.0.0.0
  System.String[] `` ``

  This method opens a file, reads each line of the file, and then adds each line as an element of a string array. It then closes the file. A line is defined as a sequence of characters followed by a carriage return ('\r'), a line feed ('\n'), or a carriage return immediately followed by a line feed. The resulting string does not contain the terminating carriage return and/or line feed.

  This method attempts to automatically detect the encoding of a file based on the presence of byte order marks. Encoding formats UTF-8 and UTF-32 (both big-endian and little-endian) can be detected.

  Opens a file, reads all lines of the file with the specified encoding, and then closes the file.

  A string array containing all lines of the file.

  The file to open for reading. The encoding applied to the contents of the file.
- Method
  2.0.0.0
  4.0.0.0
  System.String ``

  This method opens a file, reads each line of the file, and then adds each line as an element of a string. It then closes the file. A line is defined as a sequence of characters followed by a carriage return ('\r'), a line feed ('\n'), or a carriage return immediately followed by a line feed. The resulting string does not contain the terminating carriage return and/or line feed.

  This method attempts to automatically detect the encoding of a file based on the presence of byte order marks. Encoding formats UTF-8 and UTF-32 (both big-endian and little-endian) can be detected.

  Use the method overload when reading files that might contain imported text, because unrecognized characters may not be read correctly.

  The file handle is guaranteed to be closed by this method, even if exceptions are raised.

  Opens a text file, reads all lines of the file, and then closes the file.

  A string containing all lines of the file.

  The file to open for reading.
- Method
  2.0.0.0
  4.0.0.0
  System.String `` ``

  This method opens a file, reads each line of the file, and then adds each line as an element of a string. It then closes the file. A line is defined as a sequence of characters followed by a carriage return ('\r'), a line feed ('\n'), or a carriage return immediately followed by a line feed. The resulting string does not contain the terminating carriage return and/or line feed.

  This method attempts to automatically detect the encoding of a file based on the presence of byte order marks. Encoding formats UTF-8 and UTF-32 (both big-endian and little-endian) can be detected.

  The file handle is guaranteed to be closed by this method, even if exceptions are raised.

  To use the encoding settings as configured for your operating system, specify the property for the parameter.

  Opens a file, reads all lines of the file with the specified encoding, and then closes the file.

  A string containing all lines of the file.

  The file to open for reading. The encoding applied to the contents of the file.
- Method
  4.0.0.0
  System.Collections.Generic.IEnumerable<System.String> ``

  The and methods differ as follows: When you use , you can start enumerating the collection of strings before the whole collection is returned; when you use , you must wait for the whole array of strings be returned before you can access the array. Therefore, when you are working with very large files, can be more efficient.

  You can use the method to do the following:

  Perform Linq to Object queries on a file to obtain a filtered set of its lines.

  Write the returned collection of lines to a file with the method, or append them to an existing file with the method.

  Create an immediately populated instance of a collection that takes an collection of strings for its constructor, such as a or a .

  This method uses for the encoding value.

  Reads the lines of a file.

  All the lines of the file, or the lines that are the result of a query.

  The file to read.
- Method
  4.0.0.0
  System.Collections.Generic.IEnumerable<System.String> `` ``

  Use this method to specify an encoding to use read the file.

  The and methods differ as follows: When you use , you can start enumerating the collection of strings before the whole collection is returned. When you use , you must wait for the whole array of strings be returned before you can access the array. Therefore, when you are working with very large files, can be more efficient.

  You can use the method to do the following:

  Perform Linq to Object queries on a file to obtain a filtered set of its lines.

  Write the returned collection of lines to a file with the method, or append them to an existing file with the method.

  Create an immediately populated instance of a collection that takes an collection of strings for its constructor, such as a or a .

  Read the lines of a file that has a specified encoding.

  All the lines of the file, or the lines that are the result of a query.

  The file to read. The encoding that is applied to the contents of the file.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` `` ``

  The method replaces the contents of a specified file with the contents of another file. It also creates a backup of the file that was replaced.

  If the and are on different volumes, this method will raise an exception. If the is on a different volume from the source file, the backup file will be deleted.

  Pass null to the parameter if you do not want to create a backup of the file being replaced.

  Replaces the contents of a specified file with the contents of another file, deleting the original file, and creating a backup of the replaced file.

  The name of a file that replaces the file specified by . The name of the file being replaced. The name of the backup file.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` `` `` ``

  The method replaces the contents of a specified file with the contents of another file. It also creates a backup of the file that was replaced.

  If the and are on different volumes, this method will raise an exception. If the is on a different volume from the source file, the backup file will be deleted.

  Pass null to the parameter if you do not want to create a backup of the file being replaced.

  Replaces the contents of a specified file with the contents of another file, deleting the original file, and creating a backup of the replaced file and optionally ignores merge errors.

  The name of a file that replaces the file specified by . The name of the file being replaced. The name of the backup file. true to ignore merge errors (such as attributes and access control lists (ACLs)) from the replaced file to the replacement file; otherwise, false.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  The method applies access control list (ACL) entries to a file that represents the noninherited ACL list.

  The ACL specified for the parameter replaces the existing ACL for the file. To add permissions for a new user, use the method to obtain the existing ACL, modify it, and then use to apply it back to the file.

  An ACL describes individuals and/or groups who have, or do not have, rights to specific actions on the given file. For more information, see ACL Technology Overview and How to: Add or Remove an Access Control List Entry.

  The method persists only objects that have been modified after object creation. If a object has not been modified, it will not be persisted to a file. Therefore, it is not possible to retrieve a object from one file and reapply the same object to another file.

  To copy ACL information from one file to another:

  Use the method to retrieve the object from the source file.

  Create a new object for the destination file.

  Use the or method of the source object to retrieve the ACL information.

  Use the or method to copy the information retrieved in step 3 to the destination object.

  Set the destination object to the destination file using the method.

  In NTFS environments, and are granted to the user if the user has rights on the parent folder. To deny and , deny on the parent directory.

  Applies access control list (ACL) entries described by a object to the specified file.

  A file to add or remove access control list (ACL) entries from. A object that describes an ACL entry to apply to the file described by the parameter.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  Certain file attributes, such as and , can be combined. Other attributes, such as , must be used alone.

  It is not possible to change the compression status of a object using the method.

  For a list of common I/O tasks, see Common I/O Tasks.

  Sets the specified of the file on the specified path.

  The path to the file. A bitwise combination of the enumeration values.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` `` is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters. specifies a value outside the range of date/times permitted for this operation. is . was not found. An I/O error occurred while performing the operation. The length of or the absolute path information for exceeds the system-defined maximum length. Requires permission to write to the specified file or directory. See . The caller does not have the required permission.

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  NTFS-formatted drives may cache file meta-info, such as file creation time, for a short period of time. As a result, it may be necessary to explicitly set the creation time of a file if you are overwriting or replacing an existing file.

  For a list of common I/O tasks, see Common I/O Tasks.

  Sets the date and time the file was created.

  The file for which to set the creation date and time information. A containing the value to set for the creation date and time of . This value is expressed in local time. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  NTFS-formatted drives may cache file meta-info, such as file creation time, for a short period of time. As a result, it may be necessary to explicitly set the creation time of a file if you are overwriting or replacing an existing file.

  For a list of common I/O tasks, see Common I/O Tasks.

  Sets the date and time, in coordinated universal time (UTC), that the file was created.

  The file for which to set the creation date and time information. A containing the value to set for the creation date and time of . This value is expressed in UTC time.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` `` is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters. is . An I/O error occurred while performing the operation. The length of or the absolute path information for exceeds the system-defined maximum length. The caller does not have the required permission. Requires permission to write to the specified file. See . specifies a value outside the range of date/times permitted for this operation. was not found. The caller does not have the required permission.

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  For a list of common I/O tasks, see Common I/O Tasks.

  Sets the date and time the specified file was last accessed.

  The file for which to set the access date and time information. A containing the value to set for the last access date and time of . This value is expressed in local time. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  For a list of common I/O tasks, see Common I/O Tasks.

  Sets the date and time, in coordinated universal time (UTC), that the specified file was last accessed.

  The file for which to set the access date and time information. A containing the value to set for the last access date and time of . This value is expressed in UTC time.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` `` is a zero-length string, contains only white space, or contains one or more implementation-specific invalid characters. is . An I/O error occurred while performing the operation. The length of or the absolute path information for exceeds the system-defined maximum length. The caller does not have the required permission. Requires permission to write to the specified file. See . specifies a value outside the range of date/times permitted for this operation. was not found. The caller does not have the required permission.

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  For a list of common I/O tasks, see Common I/O Tasks.

  Sets the date and time that the specified file was last written to.

  The file for which to set the date and time information. A containing the value to set for the last write date and time of . This value is expressed in local time. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  The parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see .

  For a list of common I/O tasks, see Common I/O Tasks.

  Sets the date and time, in coordinated universal time (UTC), that the specified file was last written to.

  The file for which to set the date and time information. A containing the value to set for the last write date and time of . This value is expressed in UTC time.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  Given a byte array and a file path, this method opens the specified file, writes the contents of the byte array to the file, and then closes the file.

  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.

  The file to write to. The bytes to write to the file.
- Method
  4.0.0.0
  System.Void `` ``

  The default behavior of the method is to write out data by using UTF-8 encoding without a byte order mark (BOM). If it is necessary to include a UTF-8 identifier, such as a byte order mark, at the beginning of a file, use the method overload with encoding.

  If the target file already exists, it is overwritten.

  You can use this method to create the contents for a collection class that takes an in its constructor, such as a , , or a class.

  Creates a new file, writes a collection of strings to the file, and then closes the file.

  The file to write to. The lines to write to the file.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  If the target file already exists, it is overwritten.

  The default behavior of the method is to write out data using UTF-8 encoding without a byte order mark (BOM). If it is necessary to include a UTF-8 identifier, such as a byte order mark, at the beginning of a file, use the method overload with encoding.

  Given a string array and a file path, this method opens the specified file, writes the string array to the file, and then closes the file.

  Creates a new file, write the specified string array to the file, and then closes the file.

  The file to write to. The string array to write to the file.
- Method
  4.0.0.0
  System.Void `` `` ``

  If the target file already exists, it is overwritten.

  You can use this method to create a file that contains the following:

  The results of a LINQ to Objects query on the lines of a file, as obtained by using the method.

  The contents of a collection that implements an of strings.

  Creates a new file by using the specified encoding, writes a collection of strings to the file, and then closes the file.

  The file to write to. The lines to write to the file. The character encoding to use.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` `` ``

  If the target file already exists, it is overwritten.

  Given a string array and a file path, this method opens the specified file, writes the string array to the file using the specified encoding, and then closes the file.

  Creates a new file, writes the specified string array to the file by using the specified encoding, and then closes the file.

  The file to write to. The string array to write to the file. An object that represents the character encoding applied to the string array.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  This method uses UTF-8 encoding without a Byte-Order Mark (BOM), so using the method will return an empty byte array. If it is necessary to include a UTF-8 identifier, such as a byte order mark, at the beginning of a file, use the method overload with encoding.

  Given a string and a file path, this method opens the specified file, writes the string to the file, and then closes the file.

  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.

  The file to write to. The string to write to the file.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` `` ``

  Given a string and a file path, this method opens the specified file, writes the string to the file using the specified encoding, and then closes the file. The file handle is guaranteed to be closed by this method, even if exceptions are raised.

  Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. If the target file already exists, it is overwritten.

  The file to write to. The string to write to the file. The encoding to apply to the string.
0