Share via


CopyTo(String, Boolean) Method

The CopyTo method of the SPFile class copies the file to the destination URL but overwrites an existing file of the same name only if bOverwrite is true.

Parameters

strNewUrl    A string that specifies the destination URL.

bOverWrite   true to overwrite a file of the same name; otherwise false.

Remarks

The CopyTo method is used to copy files to another location within the same site. To copy files to a location in another site, use one of the Add methods of the SPFileCollectionclass.

This method returns an error if bOverWrite is set to false and a file of the same name already exists at the new location.

Example

The following code example copies all the files in the Shared Documents document library to another folder in the same site, overwriting any file of the same name.

This example requires using directives (Imports in Visual Basic) for both the Microsoft.SharePoint and Microsoft.SharePoint.WebControls namespaces.

Requirements

Platforms: Microsoft Windows Server 2003

Security: Code Access Security