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.load(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(); console.log(verification); } } function notVerified(sender, args) { alert("DAMNIT TO HELL!!"); console.log(args.get_message()); } 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.