I want to make rest call or implement some JSOM mechanism to retrieve previous version file from _vti_history.

For example: _vti_history/1024/Documents/Filename.docx

Please guide me if this is possible in some way.



1 Answer 1


You can use below to get file versions history, there is rest endpoint available which will give you all version of a file using item id, also it can be done using JSOM.



JSOM (ref link)

var oItems, clientContext, oFile, oFileVersions;
function GetAllVersions() {
    // You can optionally specify the Site URL here to get the context
    // If you don't specify the URL, the method will get the context of the current site
    // var clientContext = new SP.ClientContext("http://MyServer/sites/SiteCollection");
    clientContext = new SP.ClientContext();

    // Get List Object
    var olistCollection = clientContext.get_web().get_lists();
    var oList = olistCollection.getByTitle("Documents");

    // Get Item using CAML Query
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'FileLeafRef\'/>' + '<Value Type=\'File\'>Document.docx</Value></Eq></Where></Query></View>');
    oItems = oList.getItems(camlQuery);

    // Load List Item collection object

    // Execute the query to the server.
    clientContext.executeQueryAsync(onsuccess, onfailed);

function onsuccess() {
    // Loop through each Item.
    var itemCount = oItems.get_count();
    for (var i = 0; i <= itemCount - 1; i++) {
        // Get File object of the list item
        oFile = oItems.itemAt(i).get_file();
        oFileVersions = oFile.get_versions();


    //Execute the batch
    clientContext.executeQueryAsync(FinalQuerySuccess, FinalQueryFailure);

function onfailed(sender, args) {
    console.log('Failed' + args.get_message() + '\n' + args.get_stackTrace());

function FinalQuerySuccess(sender, args) {

    // Iterate through Enumerator
    var oEnumerator = oFileVersions.getEnumerator();
    while (oEnumerator.moveNext()) {
        var oFile = oEnumerator.get_current();
        console.log("Version Label : " + oFile.get_versionLabel());
        console.log("Version Comment : " + oFile.get_checkInComment());

function FinalQueryFailure(sender, args) {
    console.log('Failed' + args.get_message() + '\n' + args.get_stackTrace());
  • Your code gives all the version labels for the file.my requiremet is to get eaxct file of any specific version.Any idea to get it Sep 5, 2019 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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