Copies an existing file to a new file, disallowing the overwriting of an existing file.
[Visual Basic] Overloads Public Function CopyTo( _ ByVal destFileName As String _ ) As File [C#] public File CopyTo( string destFileName ); [C++] public: File* CopyTo( String* destFileName ); [JScript] public function CopyTo( destFileName : String ) : File;
A new file with a fully qualified path.
Exception Type | Condition |
---|---|
ArgumentException | The name of the source file, the destination file, or both is an empty string ("") or is all whitespaces. |
IOException | An error occurs or the destination file already exists. |
SecurityException | The caller does not have the required permission. |
ArgumentNullException | The name of the source file, the destination file, or both is a null reference (in Visual Basic Nothing). |
Copy is a static method while CopyTo is an instance method. For CopyTo, you must have created a File object, which stores the source file name. Copy allows the specifying of a source file name without having to create a File object.
Use the Copy(string, string, bool) method to allow overwriting of an existing file.
NGWS Runtime Security:
FileIOPermissionAccess | Read permission required for the source file. |
FileIOPermissionAccess | Write permission required for the destination file. |
File Class | File Members | System.IO Namespace | File.CopyTo Overload List