Take the 2-minute tour ×

I am trying to get all the children of folder (folder created in Alfresco server) using the following code

//Path is the path to the location of the folder in alfresco server
String folderId = session.getObjectByPath(path).getId();
Folder folder = (Folder) session.getObject(folderId);
if(folder.getChildren()!= null){
ItemIterable<CmisObject> childFolderIterable = folder.getChildren();
Iterator<?> childFolders = childFolderIterable.iterator();
      Folder subChildFolder = (Folder) childFolders.next();

Now my question is that folder at Alfresco contains 2 different sub-folders but the following code childFolderIterable.getHasMoreItems() returns false.

Can someone please look into this and guide me where I am wrong or is there any appropriate way to find the children of the folder?

share|improve this question
which version of Alfresco are you using? –  skuro Oct 30 '12 at 13:00

2 Answers 2

up vote 3 down vote accepted

The getHasMoreItems() method documentation says:

Returns whether the repository contains additional items beyond the page of items already fetched. Returns: true => further page requests will be made to the repository

If it returns false, it means that the page you fetched by calling getChildren() contains already all children of this folder and no further requests (to get the remaining children) are required. If you have a folder with a lot of children you can use the operation context to page the results. The OpenCMIS project site provides an appropriate example.

If you use no paging, then simply call:

Iterator<CmisObject> it = folder.getChildren().iterator();

while(it.hasNext()) {
  CmisObject object = it.next();

  // Do something with the child object

The iterator should provide the two children you are looking for.

share|improve this answer
Thanks @gclaussn your solution worked.. :) –  Milesh Oct 30 '12 at 15:16

Also it can be done in the following way:

 for(CmisObject obj: folder.getChildren()) {
        System.out.println("Name: " + obj.getName());
        System.out.println("Id: " + obj.getId());
        System.out.println("Type: " + getType(obj.getType()));
share|improve this answer

Your Answer


