none
Update file content and increase version in Document Library JSOM RRS feed

  • Question

  • Hi,

    I have been working on a webpart that update a file. This file should be updated, but not replaced. I mean this file should increase the version number and update the file content. 

    At the moment I am using JSOM. Also, I have tried CopyTo and Savebinary. The first method replace replace the file and don´t update the version. SaveBinary is not allowed on file inside a Document Library. This is the code I am using:

     
      var addFileRequest = new SP.RequestExecutor(_spPageContextInfo.webAbsoluteUrl);
            addFileRequest.executeAsync({
                url: "mysite/sites/XXXX/_api/Web/Lists(guid'0e8f7899-0c34-4f6c-9998-99bc835a1fd6')/files('4ZkO8fMXOkCGTcdXv85xoBJcb76vN2lHqFmt20jsNhHO86S3xoUMRL9iaA7i400C')/saveBinary",
               
                method: "POST",
                headers: {
                    "Accept": "application/json; odata=verbose",
                    "X-RequestDigest": digest
                },
                contentType: "application/json;odata=verbose",
                file: data.body,
                binaryStringRequestBody: true,
                state: "Update",
                success: function () {
                },
                error: function (data) {
                    console.log("Error in UpdateDocumentContent. Message: " + JSON.stringify(data));
                },

    I am sending directly the binary as you can see. The error message is:

    Message: {"state":"Update","responseAvailable":true,"body":"{\"error\":{\"code\":\"-1, Microsoft.SharePoint.Client.ResourceNotFoundException\",\"message\":{\"lang\":\"en-US\",\"value\":\"Cannot find resource for the request saveBinary.\"}}}","statusCode":404,"statusText":"Not Found","contentType":"application/json;odata=verbose;charset=utf-8","allResponseHeaders":"cache-control: private, max-age=0\r\ncontent-type: application/json;odata=verbose;charset=utf-8\r\ndataserviceversion: 3.0\r\ndate: Fri, 25 Sep 2020 23:13:23 GMT\r\nexpires: Thu, 10 Sep 2020 23:13:24 GMT\r\nlast-modified: Fri, 25 Sep 2020 23:13:24 GMT\r\nmicrosoftsharepointteamservices: 16.0.0.5044\r\nrequest-id: 7c9b7d9f-8142-c036-35f6-aed6ece1cbde\r\nserver: Microsoft-IIS/10.0\r\nspclientservicerequestduration: 80\r\nsprequestguid: 7c9b7d9f-8142-c036-35f6-aed6ece1cbde\r\ntransfer-encoding: chunked\r\nx-aspnet-version: 4.0.30319\r\nx-content-type-options: nosniff\r\nx-frame-options: SAMEORIGIN\r\nx-ms-invokeapp: 1; RequireReadOnly\r\nx-powered-by: ASP.NET\r\nx-requestdigest: 0x6912459930713DE8A64ED3D7A06F2E366358536F21E306F5DAEBB8EFE5A36F69D4F032C7A8AB38E4BD2D216C224D1C254D7F5784783464AB45FBE345A59E9B0D,25 Sep 2020 23:13:24 -0000\r\nx-sharepointhealthscore: 0\r\nx-sp-serverstate: ReadOnly=0\r\n","headers":{"CACHE-CONTROL":"private, max-age=0","CONTENT-TYPE":"application/json;odata=verbose;charset=utf-8","DATASERVICEVERSION":"3.0","DATE":"Fri, 25 Sep 2020 23:13:23 GMT","EXPIRES":"Thu, 10 Sep 2020 23:13:24 GMT","LAST-MODIFIED":"Fri, 25 Sep 2020 23:13:24 GMT","MICROSOFTSHAREPOINTTEAMSERVICES":"16.0.0.5044","REQUEST-ID":"7c9b7d9f-8142-c036-35f6-aed6ece1cbde","SERVER":"Microsoft-IIS/10.0","SPCLIENTSERVICEREQUESTDURATION":"80","SPREQUESTGUID":"7c9b7d9f-8142-c036-35f6-aed6ece1cbde","TRANSFER-ENCODING":"chunked","X-ASPNET-VERSION":"4.0.30319","X-CONTENT-TYPE-OPTIONS":"nosniff","X-FRAME-OPTIONS":"SAMEORIGIN","X-MS-INVOKEAPP":"1; RequireReadOnly","X-POWERED-BY":"ASP.NET","X-REQUESTDIGEST":"0x6912459930713DE8A64ED3D7A06F2E366358536F21E306F5DAEBB8EFE5A36F69D4F032C7A8AB38E4BD2D216C224D1C254D7F5784783464AB45FBE345A59E9B0D,25 Sep 2020 23:13:24 -0000","X-SHAREPOINTHEALTHSCORE":"0","X-SP-SERVERSTATE":"ReadOnly=0"}}

    Also, I have been reading posts like this: https://sunbin0704.wordpress.com/2013/10/11/csom-update-file-and-create-new-version-in-document-library/ Many of them are based on CSOM.

    Best regards,

    Friday, September 25, 2020 11:23 PM