Forum Discussion
Copy documents between libraries with js pnp
- Mar 19, 2017
Hi there,
It can be done with `copyTo` method. With pnp-core-js:$pnp.sp.web .getFileByServerRelativeUrl('/sites/dev01/DocLib01/tttt/Development and Deployment Guidelines.pdf') .copyTo('/sites/dev01/DocLib03/Development and Deployment Guidelines.pdf', true) .then(function(res) { console.log(res); });
Which constructs POST request to the following REST endpoint:
/_api/web /getfilebyserverrelativeurl('[server relative url of the file to copy') /copyto(
strnewurl='[server reletive url where to copy, including file name]',
boverwrite=true)--
Cheers,
Andrew
Hi there,
It can be done with `copyTo` method. With pnp-core-js:
$pnp.sp.web .getFileByServerRelativeUrl('/sites/dev01/DocLib01/tttt/Development and Deployment Guidelines.pdf') .copyTo('/sites/dev01/DocLib03/Development and Deployment Guidelines.pdf', true) .then(function(res) { console.log(res); });
Which constructs POST request to the following REST endpoint:
/_api/web /getfilebyserverrelativeurl('[server relative url of the file to copy') /copyto(
strnewurl='[server reletive url where to copy, including file name]',
boverwrite=true)
--
Cheers,
Andrew
Thanks!
A second question...is it possible to use pnp-core-js to copy file(s) to a doc lib in another sitecollection, too?
- Mar 21, 2017
Hi Jon,
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.
- Jon Ivar KlevelandMar 24, 2017Copper Contributor
Thanks.
Just would be nice to not transfer the document to the client and back. But we then have to make the solution in Azure...