FileInfo.CopyTo Method (String)
Copies an existing file to a new file, disallowing the overwriting of an existing file.
Assembly: mscorlib (in mscorlib.dll)
destFileName is empty, contains only white spaces, or contains invalid characters.
An error occurs, or the destination file already exists.
The caller does not have the required permission.
destFileName is null.
A directory path is passed in, or the file is being moved to a different drive.
The directory specified in destFileName does not exist.
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.
destFileName contains a colon (:) within the string but does not specify the volume.
Use the CopyTo method to allow overwriting of an existing file.
Whenever possible, avoid using short file names (such as XXXXXX~1.XXX) with this method. If two files have equivalent short file names then this method may fail and raise an exception and/or result in undesirable behavior
The following example demonstrates both overloads of the CopyTo method.
The following example demonstrates copying one file to another file, throwing an exception if the destination file already exists.
Available since 10
Available since 1.1
Available since 2.0
Windows Phone Silverlight
Available since 7.0