File.Replace Method (String, String, String, Boolean)
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.
Assembly: mscorlib (in mscorlib.dll)
static member Replace : sourceFileName:string * destinationFileName:string * destinationBackupFileName:string * ignoreMetadataErrors:bool -> unit
The name of a file that replaces the file specified by destinationFileName.
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.
The path described by the destinationFileName parameter was not of a legal form.
The path described by the destinationBackupFileName parameter was not of a legal form.
The destinationFileName parameter is null.
An invalid drive was specified.
The file described by the current FileInfo object could not be found.
The file described by the destinationBackupFileName parameter could not be found.
An I/O error occurred while opening the file.
- or -
The sourceFileName and destinationFileName parameters specify the same file.
The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.
The operating system is Windows 98 Second Edition or earlier and the files system is not NTFS.
The sourceFileName or destinationFileName parameter specifies a file that is read-only.
This operation is not supported on the current platform.
Source or destination parameters specify a directory instead of a file.
The caller does not have the required permission.
Themethod 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 sourceFileName and destinationFileName are on different volumes, this method will raise an exception. If the destinationBackupFileName is on a different volume from the source file, the backup file will be deleted.
Pass null to the destinationBackupFileName parameter if you do not want to create a backup of the file being replaced.
for permission to read and write to the file described by the sourceFileName parameter. Security action: Demand. Associated enumeration: FileIOPermissionAccess.Read
for permission to read and write to the file described by the destinationFileName parameter. Security action: Demand. Associated enumerations: FileIOPermissionAccess.Read, FileIOPermissionAccess.Write
for permission to write to file described by the destinationBackupFileName parameter if one is specified. Security action: Demand. Associated enumeration: FileIOPermissionAccess.Write
Available since 2.0