update the file in sharepoint library using REST
 i have followed the method what msdn suggessted .when im tryin to update the file in sharepoint lib im getting error value does not fall within the range..Anyone suggest me what wrong in this code?

// Initialize the RequestExecutor with the app web URL.
    executor = new SP.RequestExecutor(appweburl);
 alert(appweburl);

 alert(appweburl + "/_api/SP.AppContextSite(@target)/web/GetFileByServerRelativeUrl('lib/folder/cool.txt')/$value?@target='" + hostweburl + "'");
    executor.executeAsync({

   url: appweburl + "/_api/SP.AppContextSite(@target)/web/GetFolderByServerRelativeUrl('lib/folder/cool.txt')/$value?@target='" + hostweburl + "'",

       method:"POST",

        body:"Updated contents of the file go here",
          headers: {

              "X-HTTP-Method":"PUT"

            },  
success: FileSuccessHandler,
        error: FoldersErrorHandler
    });
}

                 
March 25th, 2015 2:22am

Hi,

Check if your "*.js" files have been loaded before your REST operation.

Did you try to execute the resquest through you browser ?

Regards.

Gilles Martinez
Twitter Blog
Please mark as helpful/answer if this resolved your post



Free Windows Admin Tool Kit Click here and download it now
March 25th, 2015 8:25am

GetFileByServerRelativeUrl.... since you're getting a FILE, you'll need a URL to a FILE (not just a library)... by SERVER relative URL, so you'll need to include the site collection path and such, not just the subsite relative URL.

Now working fine....

url: appweburl + "/_api/SP.AppContextSite(@target)/web/ GetFileByServerRelativeUrl('/sites/apps/Shared Documents/test.txt')/CheckOut()?@target='" + hostweburl + "'",
        method: "POST",
        data: metatdata,

March 26th, 2015 12:04am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics