You are here

You are here

Getting the contents of a folder

As its name implies, FolderGetContents is used to get the child Folder and Document objects from a parent folder.  It is often used in building a custom UI into the SpringCM folder tree as well as used in batch document processing.

Inputs

  • token – Authentication token used in all SOAP calls
  • folderId – This is the Id of the SpringCM folder of who’s contents is to be retrieved.
  • loadExtendedMetadata – Whether metadata on the folder or document is loaded, it should generally return false if the metadata is not needed for performance reasons.
  • pager – This is an SCMDocumentPager and it cannot be null, it must be created and passed in by the client.  The SortColumn and SortAscending properties allow the developer to specify how the results will be ordered when they are returned.  The StartIndex and PageSize are used to bring back subsets of the folder contents and allow the client to build paging controls.  The max PageSize recommended is 100.  For example if there 300 documents in the folder specified in the folderId parameter, then all of the documents could be retrieved with 3 calls that specify the page size of 100 for each one, and then specifying 0, 100, and 200 as the 3 StartIndex’s.

Output

The return object from this call is an SCMList.  This object has 3 properties: an array of SCMDocuments that are in the folder, an array of SCMFolders that are sub-folders of the folder passed in the folderId parameter, and the TotalRowCount, which can be used in conjunction with the SCMDocumentPager to build paging controls or to loop and pull all items from the folder when there are more than 100 items in it.

Vertical Tabs

c#
//This is the parent folder, we will retrieve all child documents and folders
string folderId = "<Folder Id retrieved by other method calls>";
 
//We need retrieve in pages, max pagesize is 100
//We could expose the paging mechanism in a custom user interface,
//in this example we just get everything
var pager = new SCMDocumentPager {PageSize = 100, StartIndex = 0, SortColumn = SCMDocumentSortColumn.Name};
 
//Variables to store the child document and folder objects
List<SCMDocument> childDocuments = new List<SCMDocument>();
List<SCMFolder> childFolders = new List<SCMFolder>();
 
//Loop until we have gotten all the children
bool finishedRetrievingAllDocsAndFolders = false;
while (!finishedRetrievingAllDocsAndFolders)
{
	//Get a page of documents/folders
	SCMList pageOfDocsAndFolders = springCMService.FolderGetContents(token, folderId, false, pager);
	childFolders.AddRange(pageOfDocsAndFolders.SCMFolders);
	childDocuments.AddRange(pageOfDocsAndFolders.SCMDocuments);
 
	//Increment the start index to the next page
	pager.StartIndex = pager.StartIndex + pager.PageSize;
 
	//Check if we are done
	if (pageOfDocsAndFolders.TotalRowCount <= pager.StartIndex)
	{
		finishedRetrievingAllDocsAndFolders = true;
	}
}
 
Console.WriteLine("Retrieved {0} child documents and {1} child folders from parent folder {2}",childDocuments.Count,childFolders.Count,folderId);
java
//This is the parent folder, we will retrieve all child documents and folders
String folderId = "<Folder Id retrieved by other method calls>";
 
//We need retrieve in pages, max pagesize is 100
//We could expose the paging mechanism in a custom user interface,
//in this example we just get everything
SCMDocumentPager pager = new SCMDocumentPager(); 
pager.setPageSize(100);
pager.setStartIndex(0);
pager.setSortColumn(SCMDocumentSortColumn.Name);
 
//Variables to store the child document and folder objects
List<SCMDocument> childDocuments = new ArrayList<SCMDocument>();
List<SCMFolder> childFolders = new ArrayList<SCMFolder>();
 
//Loop until we have gotten all the children
Boolean finishedRetrievingAllDocsAndFolders = false;
while (!finishedRetrievingAllDocsAndFolders)
{
	//Get a page of documents/folders
	SCMList pageOfDocsAndFolders = springCMService.folderGetContents(token, folderId, false, pager);
	childFolders.addAll(Arrays.asList(pageOfDocsAndFolders.getSCMFolders()));
	childDocuments.addAll(Arrays.asList(pageOfDocsAndFolders.getSCMDocuments()));
 
	//Increment the start index to the next page
	pager.setStartIndex(pager.getStartIndex() + pager.getPageSize());
 
	//Check if we are done
	if (pageOfDocsAndFolders.getTotalRowCount() <= pager.getStartIndex())
	{
		finishedRetrievingAllDocsAndFolders = true;
	}
}
 
System.out.format("Retrieved %s child documents and %s child folders from parent folder %s",childDocuments.size(),childFolders.size(),folderId);