Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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.
strNewUrl A string that specifies the destination URL.
bOverWrite true to overwrite a file of the same name; otherwise false.
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.
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.
Platforms: Microsoft Windows Server 2003
Security: Code Access Security