I'm looking for some samples using PnP js to copy documents between libraries in SPO.
(I've tries Binging etc...)
View best response
Hi there,It can be done with `copyTo` method. With pnp-core-js:
.getFileByServerRelativeUrl('/sites/dev01/DocLib01/tttt/Development and Deployment Guidelines.pdf')
.copyTo('/sites/dev01/DocLib03/Development and Deployment Guidelines.pdf', true)
Which constructs POST request to the following REST endpoint:
/getfilebyserverrelativeurl('[server relative url of the file to copy')
/copyto( strnewurl='[server reletive url where to copy, including file name]', boverwrite=true)
A second question...is it possible to use pnp-core-js to copy file(s) to a doc lib in another sitecollection, too?
Nope, it doesn't seem to be possible with REST.
CopyTo method works within single SPWeb.
Though, it's possible to get a file's blob/buffer and metadata and create a new document in other SPSite/SPWeb using REST and pnp js core.
Just would be nice to not transfer the document to the client and back. But we then have to make the solution in Azure...
How can we maintain versioning in the target library while copying the files from Source to target, if the target library has versioning enable. Please suggest!
bump - any progress on this ?