NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

File.CopyTo (String, Boolean)

Copies an existing file to a new file, allowing the overwriting of an existing file.

[Visual Basic]
Overloads Public Function CopyTo( _
   ByVal destFileName As String, _
   ByVal overwrite As Boolean _
) As File
[C#]
public File CopyTo(
   string destFileName,
   bool overwrite
);
[C++]
public: File* CopyTo(
   String* destFileName,
   bool overwrite
);
[JScript]
public function CopyTo(
   destFileName : String,
   overwrite : Boolean
) : File;

Parameters

destFileName
The name of the new file to copy to.
overwrite
true if an existing file may be overwritten, false otherwise.

Return Value

A new file, or an overwrite of an existing file.

Exceptions

Exception Type Condition
ArgumentException The name of the source file, the destination file, or both an empty string ("") or is all whitespaces.
IOException An error occurs or the destination file already exists and overwrite is false.
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).

Remarks

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.

Requirements

NGWS Runtime Security:

FileIOPermissionAccess Read permission required for the source file.
FileIOPermissionAccess Write permission required for the destination file.

See Also

File Class | File Members | System.IO Namespace | File.CopyTo Overload List