Skip to content

Instantly share code, notes, and snippets.

@phillipharding
Last active July 18, 2022 14:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillipharding/7031a510ce76c72d41b653076ff838a1 to your computer and use it in GitHub Desktop.
Save phillipharding/7031a510ce76c72d41b653076ff838a1 to your computer and use it in GitHub Desktop.
SP.MoveCopyUtil.CopyFileByPath()

References

When overwrite is true and KeepBoth is true the destination file is overwritten.

When overwrite is true and KeepBoth is false, or

When overwrite is false and KeepBoth is false

the destination file is not overwritten and a new file with a duplicate avoiding filename is created - i.e. a number is appended to the filename to avoid a duplicate.

REQUEST

POST https://platinumdogsconsulting.sharepoint.com/sites/hubsitetest/_api/SP.MoveCopyUtil.CopyFileByPath()
HEADERS
{
   Accept: application/json;odata=nometadata
   Content-Type: application/json;odata=nometadata
   X-RequestDigest:{{formDigest}}
}
BODY
{
    "srcPath": {
        "DecodedUrl": "https://platinumdogsconsulting.sharepoint.com/sites/hubsitetest/EdmsTestDocLib/Folder 1/Folder 1-1/downhill-freestanding-718824-contract-135.docx"
    },
    "destPath": {
        "DecodedUrl": "https://platinumdogsconsulting.sharepoint.com/sites/hubsitetest/Edwards Active Documents/Folder 01/downhill-freestanding-718824-contract-135.docx"
    },
    "overwrite": true,
    "options": {
        "KeepBoth": false,
        "ResetAuthorAndCreatedOnCopy": false,
        "ShouldBypassSharedLocks": true
    }
}

RESPONSE

HTTP STATUS CODE: 200
BODY
{
    "odata.null": true
}

RESPONSE WHEN A DUPLICATE FILE IS PRESENT AT DESTINATION When overwrite is false and KeepBoth is false

HTTP STATUS CODE: 400
BODY
{
    "odata.error": {
        "code": "-2130575257, Microsoft.SharePoint.SPException",
        "message": {
            "lang": "en-US",
            "value": "The destination file already exists."
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment