CopyDocument
Copies a document to a specified destination within SharePoint. Helps in content duplication and archiving.
Execute
If the NewDocumentName parameter is not specified, the value specified in DocumentName will be used as the destination path. If the NewDocumentLibrary parameter is not specified, the value specified in DocumentLibrary will be used as the new library. In any case, at least one of these two parameters must be specified (they can't both be unspecified at the same time). The DocumentLibrary and DocumentName parameters on the other hand are always required. Refer to the query examples below:
EXEC CopyDocument DocumentLibrary = 'Documents', DocumentName = 'Source Folder/Subfolder/Source Document.txt', NewDocumentName = 'Destination Document.txt'; EXEC CopyDocument DocumentLibrary = 'Documents', DocumentName = 'Source Document.txt', NewDocumentLibrary = 'Destination Library'; EXEC CopyDocument DocumentLibrary = 'Documents', DocumentName = 'Source Folder/Subfolder/Source Document.txt', NewDocumentLibrary = 'Destination Library', NewDocumentName = 'Destination Document.txt';If the NewDocumentName parameter is a folder (ends with a '/'), the document name from DocumentName will be used as the new file name instead. Refer to the query example below:
EXEC CopyDocument DocumentLibrary = 'Documents', DocumentName = 'Source Folder/Subfolder/Source Document.txt', NewDocumentLibrary = 'Destination Library', NewDocumentName = 'Destination Folder/Subfolder/';
Additionally, you can copy the document to a different site in your SharePoint instance by specifying its full URL. In this scenario, NewDocumentLibrary is required. Refer to the query example below:
EXEC CopyDocument DocumentLibrary = 'Documents', DocumentName = '/Source Folder/Subfolder/Source Document.txt', NewDocumentLibrary = 'Destination Library', NewDocumentName = 'https://mysite.sharepoint.com/sites/Destination%20Site/Destination%20Library/Destination%20Folder/Subfolder/Destination%20Document.txt';
Input
| Name | Type | Required | Description |
| DocumentName | String | True | The relative path of the original document within its document library. Example: 'Folder1/OriginalFile.docx'. |
| DocumentLibrary | String | True | The display name of the SharePoint document library where the original document is stored. Example: 'Shared Documents'. |
| NewDocumentLibrary | String | False | The display name of the target document library where the copied document will be stored. If left blank, the document remains in the same library as the original. |
| NewDocumentName | String | False | The relative path and file name for the copied document in the new library. If left blank, the document retains the same name as the original. |
Result Set Columns
| Name | Type | Description |
| Success | Boolean | Indicates whether the document copy operation was successful. Returns 'true' for success and 'false' for failure. |
| Id | String | The unique identifier assigned to the copied document after completion. |
| DocumentId | String | The document ID assigned to the copied file. |
| DocumentIdUrl | String | The URL where the copied document can be accessed via its document ID. |
| FileRef | String | The SharePoint file reference path of the copied document. |