CopyTo(String) Method

The CopyTo method of the SPFile class copies the file to the destination URL but does not overwrite an existing file of the same name.

Parameters

strNewUrl   A string that specifies the destination URL.

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 a file of the same name already exists at the new location.

Example

The following code example copies files from one document library into another one if the files are checked into the original library with the comment "Complete".

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