File.Copy Method (String, String, Boolean)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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

Namespace:   System.IO
Assembly:  mscorlib (in mscorlib.dll)

static member Copy : 
        sourceFileName:string *
        destFileName:string *
        overwrite:bool -> unit


Type: System.String

The file to copy.

Type: System.String

The name of the destination file. This cannot be a directory.

Type: System.Boolean

true if the destination file can be overwritten; otherwise, false.

Exception Condition

The caller does not have the required permission.


destFileName is read-only.


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


sourceFileName or destFileName specifies a directory.


sourceFileName or destFileName is null.


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 path specified in sourceFileName or destFileName is invalid (for example, it is on an unmapped drive).


sourceFileName was not found.


destFileName exists and overwrite is false.


An I/O error has occurred.


sourceFileName or destFileName is in an invalid format.

The sourceFileName and destFileName 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.

The following example copies files to the C:\archives\2008 backup folder. It uses the two overloads of the Copy method as follows:

  • It first uses the File.Copy(String, String) method overload to copy text (.txt) files. The code demonstrates that this overload does not allow overwriting files that were already copied.

It then uses the File.Copy(String, String, Boolean) method overload to copy pictures (.jpg files). The code demonstrates that this overload does allow overwriting files that were already copied.

No code example is currently available or this language may not be supported.


for reading from sourceFileName and writing to destFileName. Associated enumerations: FileIOPermissionAccess.Read, FileIOPermissionAccess.Write

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top