Welcome to the new Box Support website. Check out all the details here on what’s changed.

How to get the Version Number of the Previous File Versions?

Answered
New post

Comments

4 comments

  • Murtza

     You can use the Get Versions endpoint to get information about previous versions of a file. 

    0
    Comment actions Permalink
  • arunk-vg

    Actually using the BOX-SDK, I wanted to fetch the previous version number of the versions,

    like info.getVersionNumber() method, i want to get the previous versions version number.

    0
    Comment actions Permalink
  • kendomen
            BoxFile file = new BoxFile(userApi, "xxxxxx");
            System.out.println("file current version: " + file.getInfo().getVersion().getVersionID());
    
            Collection versions = file.getVersions();   // Fetching the Previous Version of the Files
            int versionIndex = versions.size();
            if (versions.size() != 0) {     // If there is no Previous Versions
                for (BoxFileVersion bfv : versions) {
                    if (versionIndex == versions.size())  // the first one is the previous version
                    {
                        bfv.promote();
                        bfv.delete();
                        System.out.println("Deleted Version ID : "+ bfv.getVersionID());
                    }
                    System.out.println("bfv: [" + versionIndex-- + "] " + bfv.getVersionID() + " " + bfv.getCreatedAt());
                }
            }
    0
    Comment actions Permalink
  • arunk-vg

    I think one more condition to be added to the code given by , for checking the Trashed previous versions. Correct me if i am wrong.      

             

     if(bfv.getTrashedAt() == null){
                    bfv.promote();
                    bfv.delete();
                    System.out.println("Deleted Version ID : "+ bfv.getVersionID());
     }

     

    0
    Comment actions Permalink

Please sign in to leave a comment.