2

I have this piece of code:

Folder fold = Factory.Folder.fetchInstance(os, folderPath, null);
DocumentSet docs = fold.get_ContainedDocuments();
Iterator it = docs.iterator();

Document retr;
try {
    while (it.hasNext()) {
        retr = (Document)it.next();
        String name = retr.get_Name();
        System.out.println(name);

        if(name.equals(fileName)) {
            System.out.println("Match Found");
            System.out.println("Document Name : " + retr.get_Name());
            return retr;
        }
    }
} catch (Exception e) {
    e.printStackTrace();
}

Currently, this code works fine for retrieving a document with a certain file name. I want to add to this so that it can also select the latest version of the file with that name. What should i do?

I've considered adding an extra if inside the existing one, but i'm afraid of impacting the performance.

WiredCoder
  • 916
  • 1
  • 11
  • 39
  • I don't think that performance is a problem. Why not try it and measure it for yourself and post maybe the result as an answer. – Lino Oct 30 '17 at 12:45
  • 2
    Your title doesn't really match your question. Are you trying to sort, or are you just trying to retrieve a certain document on request? – Christopher Powell Oct 31 '17 at 15:45
  • @ChristopherPowell i'm trying to retrieve the document. maybe my phrasing is confusing. – user3871512 Nov 23 '17 at 06:49

2 Answers2

1

this is what you can do to get the latest version of the document

    Folder fold = Factory.Folder.fetchInstance(os, folderPath, null);
        DocumentSet docs = fold.get_ContainedDocuments();
        Iterator it = docs.iterator();

        Document retr;
        try {
            while (it.hasNext()) {
                retr = (Document)it.next();
                String name = retr.get_Name();
                System.out.println(name);

                if(name.equals(fileName)) {

                    System.out.println("Match Found");
                    System.out.println("Document Name : " + retr.get_Name());
//here you are checking the document for the name. It also can happen that, this document might have more than version but the title remained same for each version. You can get the latest version like

                    return retr.get_CurrentVersion();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
bajji
  • 1,271
  • 3
  • 15
  • 37
0

If you are filing a Document (or a subclass of Document), the contained document will be the current document version. In this case, the current document version is (in order of use):

  • the released version (if there is one), else
  • the current version (if there is one), otherwise,
  • the reservation version.

You cannot use the Folder.file method to file a specific document version into the folder, and hence you will always have the DocumentSet with the latest version in the folder

WiredCoder
  • 916
  • 1
  • 11
  • 39