Showing posts with label site collection. Show all posts
Showing posts with label site collection. Show all posts

Thursday, July 3, 2014

Copy a file across site collections with REST

I had to give the users the possibility to copy a file from the SharePoint search results to a document library in another site collection. This requirement resulted in the following custom display template: when clicking the 'Copy to other site collection' button, a div is expanded and shows a text box to provide a new filename and 2 radio buttons to select the target document library.



All the code is based on the example from Mikael Svenson. Since he is copying a file from appweb to hostweb he is using the SP.REquestExector javascript library. When I first read his article I thought this technique wasn't usable for my problem because I was going to copy files within the same domain.

Altough the SP.RequestExecutor library is a cross-domain javascript libary, this library is perfectly usable to use within the same domain. And it is fixed, so the patching described by Mikael isn't required anymore :)

This example was built for SharePoint 2013 online but works on premise as well.