Forum Discussion

Si_Da's avatar
Si_Da
Brass Contributor
Apr 10, 2019
Solved

How to get current version of a document on Sharepoint?

How can I get the current version of a document on Sharepoint?  I've successfully done a GET List Versions, GET Version and GET Major Version but none of them return the current version.

 

  • Deleted's avatar
    Deleted
    Apr 11, 2019

    Hey Si_Da ,

     

    Just figured how you can get the Item versions from the URL.

     

    You'll need 2 REST calls.

     

    The first is _api/web/getFileByServerRelativeUrl('{filePath}')/listItemAllFields. This call should give you some important info about the file, including the field "OData__UIVersionString" that I first mentioned, which give you the current file version. If you want to get all versions from there, you can use the field "odata.editLink", which contains the an URL string to the Item containing the file. So you can just append this URL to your site relative URL and add "/versions" to the end. Something like "tenant.sharepoint.com/sites/{sitename}/_api/Web/Lists(listID)/Items({itemID})/versions"

     

    let me know if it helps.

21 Replies

  • Hey Si_Da,

     

    The version of a document is given by the OData__UIVersionString parameter returned in the REST call.  https://sharepoint.stackexchange.com/questions/183993/get-current-sharepoint-file-version-using-rest-call answer shows how to query the version for a specific documents or all documents in a list or library.

     

    Regards.

    • Si_Da's avatar
      Si_Da
      Brass Contributor

      Deletedfirstly thank you so much for replying!

       

      I have already looked at that example, however it is retrieving the information from a list and I want to specify the filename, e.g.

       

      .../_api/web/getFileByServerRelativeUrl('/sites/{SiteName}/Shared%20Documents/{FilenameAndPath}')/...

      • Deleted's avatar
        Deleted

        So, is there a constraint from using the Item ID instead of the File Path? Getting the Item gives you advantages such as getting all the versions, if you wish to.

         

        Anyway, this query you mentioned above should have the UIVersionLavel field, which contains the current version for the Item, right? 

Resources