SOLVED
Home

Copy documents between libraries with js pnp

Highlighted
Jon Ivar Kleveland
Occasional Contributor

Copy documents between libraries with js pnp

Hi,

I'm looking for some samples using PnP js to copy documents between libraries in SPO.

(I've tries Binging etc...)

 

 

Any?

6 Replies
Solution

Re: Copy documents between libraries with js pnp

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

Re: Copy documents between libraries with js pnp

Thanks!

 

A second question...is it possible to use pnp-core-js to copy file(s) to a doc lib in another sitecollection, too?

Re: Copy documents between libraries with js pnp

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.

Re: Copy documents between libraries with js pnp

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...

Re: Copy documents between libraries with js pnp

Hello,

 

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!

Thanks!!

Re: Copy documents between libraries with js pnp

bump - any progress on this ?

Related Conversations
copying from excel to text goes wrong, how to solve
Friso de Boer in Excel on
1 Replies
Copying Data from a New Workbook
Darrell Salvant in Macros and VBA on
0 Replies
Set Default to Copy and Paste Visible Cells Only
Karen Arigo in Excel on
1 Replies
Excel - hyperlinks
jack bloedeorn in Excel on
1 Replies