0

I am using SP.Web.getFileByServerRelativeUrl(fileurl) function of sp.js library. My site hierarchy is like this

Host Web
  App1 Web
     DocumentLibrary1
  App2 Web

wher App1 Web is a web created by my sharepoint 2013 app 1, and App2 Web is a web created by my sharepoint 2013 app 2. In app2 i try to get a file from App1 Web->DocumentLibrary1. here is my code

var ctx = SP.ClientContext.get_current();
var appctx = new SP.AppContextSite(ctx, 'hostweburl/app1');
var file = appctx.get_web().getFileByServerRelativeUrl("/DocumentLibrary1/myfile.xml");
ctx.load(file);
ctx.executeQueryAsync(function () {
    var title = file.get_title();
}, this.onError);

but i get an error "Value doesn't fall within the expected range". Seems "/DocumentLibrary1/myfile.xml" is not a server relative url of the file. I also tried "/app1/DocumentLibrary1/myfile.xml" which is not working too. Who can help

Uyghur Lives Matter
  • 18,820
  • 42
  • 108
  • 144
  • As the methodname says, you should use full path without server name, so it would be '/hostweburl/app1/DocumentLibrary1/myfile.xml' – Marek Kembrowski Jan 28 '14 at 14:45

1 Answers1

1

Put /sites//DocumentLibrary1/myfile.xml as getFileByServerRelativeUrl parameter takes

relative url with respect to server url.

for eg: "http:///sites/sitename/list/folder"

give "sites/sitename/list/folder" in server relative url.