Mono Class Library: System.IO.File Overview | Members

System.IO.File.Copy Method

Copies the specified file to a new location. [Edit]

public static void Copy (string sourceFileName, string destFileName, bool overwrite)

Parameters

sourceFileName
A string containing the name of the file to copy. [Edit]
destFileName
A string containing the name of the destination file. Cannot specify the name of a directory. [Edit]
overwrite
A bool value. Specify true if the destination file can be overwritten; otherwise false. [Edit]

Permissions

TypeReason
System.Security.Permissions.FileIOPermission [Edit] Requires permission to read the source file and write the destination file. See System.Security.Permissions.FileIOPermissionAccess.Read and System.Security.Permissions.FileIOPermissionAccess.Write.

Exceptions

TypeReason
System.IO.IOException

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

-or-

An I/O error occurred.

[Edit]
ArgumentNullExceptionsourceFileName or destFileName is null. [Edit]
ArgumentException

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

-or-

sourceFileName or destFileName specifies a directory.

[Edit]
System.Security.SecurityExceptionThe caller does not have the required permission. [Edit]
System.IO.DirectoryNotFoundExceptionDirectory information in destFileName or sourceFileName was not found. [Edit]
System.IO.FileNotFoundExceptionsourceFileName was not found. [Edit]
System.IO.PathTooLongExceptionThe length or the absolute path information for sourceFileName or destFileName exceeds the system-defined maximum length. [Edit]
UnauthorizedAccessExceptionThe caller does not have the required permission. [Edit]

Remarks

The sourceFileName and destFileName arguments are permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory.
Note: To obtain the current working directory, see Directory.GetCurrentDirectory.
[Edit]

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0