I am trying to fire some real basic CSOM calls by button clicks on an HTML form. The only problem is the form needs to be located on one site and the SP.file objects might be located on another site. I thought you could do this cross site but I am finding I was wrong.. Most of the solutions I see involve "SPfile" but I do not have access to that.. I think because I only have client permissions? This code throws the error "Value does not fall within the expected range." if verifyLocation is a URL to a site other than where the HTML button exists.

    var files;
    var verifyLocation = "/site/loc1/loc2/loc3/folder/";
    function verify()
        var context = SP.ClientContext.get_current();
        var web = context.get_web();
        var folder = web.getFolderByServerRelativeUrl(verifyLocation);
        files = folder.get_files();

        context.executeQueryAsync(Function.createDelegate(this, this.Verified), Function.createDelegate(this, this.notVerified));   

    function Verified()
        var listItemEnumerator = files.getEnumerator();
        while (listItemEnumerator.moveNext())
            var verification = listItemEnumerator.get_current().get_serverRelativeUrl();

    function notVerified(sender, args)
        alert("DAMNIT TO HELL!!");

When I run this code if verifyLocation is set to a location on the same site as my button, the code works.. I thought the use of serverRelativeUrl implies that you can use this code as long as your are on the same server.

I have also tried this code with

var context = new SP.ClientContext(verifyLocation); 

But if I do that I simply get "Unknown Error."

This code is just a model for my CSOM functions. Eventually I want to use file.copyTo() to move form one site to another with only the source and target URL. (I have it working with files on the same site, same errors if I try cross site though.) For some reason I recall reading somewhere that cross site copying was possible with Client Object Model.

If this simply is not possible with Client Object Model, please let me know and I will close out the question.

  • Have you tried the actual web url when creating the context instead of the folder url?
    – wjervis
    Commented Aug 28, 2015 at 15:29

2 Answers 2


You can use getFolderByServerRelativeUrl only in your current web (website). You cannot go to another website, because you are asking web.getFolderByServerRelativeUrl - if you want to get the file from another website, ask that website.

In SP2013 I would advise you to use REST api. https://msdn.microsoft.com/en-us/library/office/dn450841.aspx

Since your problem regards copying a document, have you considered using a workflow? https://social.msdn.microsoft.com/Forums/sharepoint/en-US/2dee7660-ab6a-4853-925f-f7949d378b44/send-document-to-repository

  • He's using SP 2010. The link that you've provided is for 2013.
    – Akhoy
    Commented Aug 28, 2015 at 15:14
  • Workflows can't operate across different sites either can they? At least in my experience that was the case. Anyway thank you for your answer. We are migrating to 2013 in october so life will be better then. I already solved my issue using jquery.sharepointservices. I'll post the answer and close out the question.
    – Riggy
    Commented Aug 28, 2015 at 15:25
  • Oh by the way. You said "ask that website" If I am doing var context = new SP.ClientContext(verifyLocation); and then context.get_web()... Isnt that asking that website? Why can't I get that website by putting it in the ClientContext constructor?????
    – Riggy
    Commented Aug 28, 2015 at 15:30

I asked a question with an impossible solution. However..

By using Realistic's solution on this question Copy document from one site to another..? I was able to perform most of the actions I needed to using Jquery SharePoint services.

It was pretty simple to find examples of all the SPservices actions I needed just by searching google.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.