2

I want to update a file in SharePoint document library with the following code. As descriptions in: http://msdn.microsoft.com/en-us/library/office/dn450841(v=office.15).aspx#bk_FileRequestExamples http://msdn.microsoft.com/en-us/library/office/dn292553(v=office.15).aspx#Files

The executeAsync returns successful but the file isn’t update! Can anybody help!?

var spUrl = appWebUrl + "/_api/SP.AppContextSite(@target)/web/GetFileByServerRelativeUrl('" + itemUrl + "')/$value?@target='" + hostWebUrl + "'";
    var executor = new SP.RequestExecutor(appWebUrl);
    executor.executeAsync(
    {
        url: spUrl,
        type: "POST",
        body: "Here is the new Body",
        headers: {
            "X-HTTP-Method": "PUT",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: readContents,
        error: errorHandler,
        state: "Update"
    });
DaNeSh
  • 1,022
  • 1
  • 14
  • 24

3 Answers3

2

In the add method it gives me the error message!!!!

So I find out I should use "method" instead of "type" when I update.

Sheena
  • 15,590
  • 14
  • 75
  • 113
DaNeSh
  • 1,022
  • 1
  • 14
  • 24
1

Based on MSDN documentation https://msdn.microsoft.com/en-us/library/office/dn735924.aspx#properties you have to use: url, method, headers, success and error

sia
  • 46
  • 4
1

had the same problem. changing

body: "Here is the new Body", 

to

data: "Here is the new Body",

solved the issue for me

Tinu
  • 11
  • 1