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.
Really nice code, just what i needed! Thank you! Is it possible to get a look at the displaytemplate you used?
ReplyDeletethanks, send me an email and I will get back to you with a preview.
ReplyDeleteHello amazing sample, works just fine! Saved me a lot of time.
ReplyDeleteThank you, keep it up,
VB
you're welcome. Good to hear.
DeleteThanks, this is super!
ReplyDeleteUseful blog...Does this code copy the document properties associated with the document ?
ReplyDeleteNo, but you can set the metadata afterwards. Please check this post: http://sanderlesage.blogspot.be/2014_12_01_archive.html
DeleteI explain how you can change metadata of a new file.
When I run this code in O365 against an image (PNG, JPG) file, the file on the target site is corrupt (displays as a broken image). How did you overcome this issue?
ReplyDeleteare you sure you've set property binaryStringRequestBody: true in both GET and POST request? I've had corrupted files as well before setting this property. Though, I've never tested with image files.
DeleteYes, I'm certain. Images (and maybe binary fines in general) apparently require something else. I've even tried adding transformRequest: [] as a RequestExecutor parameter but the image always gets corrupted.
Deleteok, hope I find some time to check this as well. Please let me know if you've found a solution :)
DeleteDid u find a solution for binary/image files?
ReplyDeletehaven't tried it myself for image files.
DeleteHi! I tried this but it throws the ret-error described in Mikael's blog... :/
ReplyDeleteSharePoint Online, On-Prem? Sure your farm is up-to-date?
DeleteHi, what are those parameters meant? specially the contextId, can you give me a more descriptive usage of this awesome function? any response will be great. Thank you!
ReplyDeleteI had the same question... where do we get the "contextId"? There is no "ctxData" array in the page.
DeleteI have a situation where I need to give users the ability copy a whole document library to another site. Would that be as simple as putting this code in a loop or would I run into problems if I do that?
ReplyDeletehi Kees, take a look at the example described here: http://sharepoint.stackexchange.com/questions/114033/how-do-i-move-files-from-one-document-library-to-another-using-jsom
DeleteHi, It is not working for me.. I am getting ret is not defined
ReplyDeleteWill the copy operation copies the metadatas and version history?
ReplyDeleteTried the solution and created the file successfully but there's being a problem that the file created is in lock state, due to which i am not able to delete the file.
ReplyDeleteIf i run my code again to create the same file then it prompt and Error 423.
Great Post .
ReplyDeleteI changed little bit in the code and it worked for me in Javascript.
It amazing. ..
:)