Copies an existing file to a new file, not allowing an existing file to be overwritten.
[Visual Basic] Overloads Public Shared Sub Copy( _ ByVal sourceFileName As String, _ ByVal destFileName As String _ ) [C#] public static void Copy( string sourceFileName, string destFileName ); [C++] public: static void Copy( String* sourceFileName, String* destFileName ); [JScript] public static function Copy( sourceFileName : String, destFileName : String );
Exception Type | Condition |
---|---|
ArgumentException | sourceFileName or destFileName is an empty string ("") or contains only whitespaces. |
ArgumentNullException | sourceFileName or destFileName is a null reference (in Visual Basic Nothing). |
IOException | An error occurs, or the destination file already exists. |
SecurityException | The caller does not have the required permission. |
FileNotFoundException | sourceFileName cannot be found. |
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.
NGWS Runtime Security:
FileIOPermissionAccess | Write permission required for the destination path. |
File Class | File Members | System.IO Namespace | File.Copy Overload List