I want to get the file of specific previous versions using java script object model in SharePoint 2013 environment.

Please share the code if any one is already worked on similar requirement.



  • Do you wan the solution using JSOM only? Or you can also use SharePoint REST api? – Ganesh Sanap Aug 29 at 13:21

Using JSOM:

You can use the below sample code that uses the restoreByLabel method to restore the previous version of the document:

<script language="javascript" type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript">  
    $(document).ready(function() {
       SP.SOD.executeFunc('sp.js', 'SP.ClientContext',restoreFile);

    var oFile;
    function restoreFile() {
        //Get client context and web
        clientContext = new SP.ClientContext();
        var oWeb = clientContext.get_web();
        //Get File object and restore a specific version

        //Load Client Context and execute the batch
        clientContext.executeQueryAsync(QuerySuccess, QueryFailure);
    function QuerySuccess() {
        //Get major version
        var majorVersion =oFile.get_majorVersion();
       console.log("Version Restored . New Major Version - "+ majorVersion );

    function QueryFailure(sender,args) {
       console.log('Request failed - '+args.get_message());


You can use below endpoint to get all version of file:


Get current SharePoint file version using REST call

  • Thanks for the code Ganesh. My concern is I want the file object which is itself a previous version document object and going forward I will consume that file object and upload the same in some other library. Here in the code you are trying to restore the previous version. – Kailash Sahoo Aug 30 at 7:24
  • Can anyone please suggest the way to get the specific version file? – Kailash Sahoo Aug 30 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.