I am busy writing some javascript to take a list of selected documents and do some processing on a list with each document in Office365. I am getting a strange error when the code tries to load the document from the absolute URL. The document is guaranteed to be in the same SP.Web
that the JS is in.
The error is
Value does not fall within the expected range.
Below is the JS I have:
function GetFile(attachment, item) {
var fileContext = SP.ClientContext.get_current();
var site = fileContext.get_site();
fileContext.load(site);
fileContext.executeQueryAsync(function() {
var relUrl = attachment.Url.replace(_spPageContextInfo.siteAbsoluteUrl, '');
var file = fileContext.get_web().getFileByServerRelativeUrl(relUrl);
fileContext.load(file, 'ListItemAllFields');
fileContext.executeQueryAsync(
function () {
var listItem = file.get_listItemAllFields();
},
function (sender, args) {
console.log(args.get_message()); //errorhandling
}
);
}, function(sender, args) {
console.log(args.get_message());
});
}
This is not a permissions thing as I can take the url of the documents being selected and open them fine from the browser.
I have noticed, that I can't seem to hit the client.svc
service on the site in question when taking the url for the request from the request object.