2

我有这段代码:

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();
}

目前,此代码适用于检索具有特定文件名的文档。我想添加它,以便它还可以选择具有该名称的文件的最新版本。我应该怎么办?

我已经考虑在现有的内部添加一个额外的,但我害怕影响性能。

4

2 回答 2

1

这是您可以获得最新版本文档的方法

    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();
        }
于 2017-11-21T20:28:26.883 回答
0

如果您正在提交文档(或文档的子类),则包含的文档将是当前文档版本。在这种情况下,当前文档版本是(按使用顺序):

  • 发布的版本(如果有),否则
  • 当前版本(如果有),否则,
  • 预订版本。

您不能使用该Folder.file方法将特定文档版本归档到文件夹中,因此您将始终DocumentSet在文件夹中拥有最新版本的文件

于 2017-11-17T23:47:28.583 回答