Documentation Center

Example of XML returned by GetListItems()

This topic provides a typical example of a GetListItems() call and the XML the call returns.

Retrieving Components from a Folder based on a certain Schema

The following code retrieves all Components from a specific Folder that are based on a certain Schema. This example assumes the following:

  • You are editing a C# fragment or .NET assembly code for a Template Building Block to include in a Component Template.
  • You want to examine the Folder in which the current Component resides.
  • You have a object (called articleSchema in this example) of class Schema that represents the Schema you are looking for.
// Create an object of class OrganizationalItemItemsFilter to filter retrieved content items.
OrganizationalItemItemsFilter filter = new OrganizationalItemItemsFilter(engine.GetSession());
// Filter out all items that are based on the Schema called articleSchema.
filter.BasedOnSchemas = new Schema[] { articleSchema };
// Make the call to GetListItems() using this OrganizationalItemItemsFilter object.
// For each item, the default set of items is returned.
// The call is made from the Organizational Item (that is, the Folder)
// that contains the Component contained within the current Component Presentation.
Component currentComponent = (Component) engine.GetSession().GetObject(package.GetValue("Component.ID"));
XmlElement list = currentComponent.OrganizationalItem.GetListItems(filter);

This returns an XML string such as the one displayed here:

<tcm:ListItems xmlns:tcm="http://www.tridion.com/ContentManager/5.0" ID="tcm:32-1993-2" Managed="10682">
	<tcm:Item ID="tcm:41-420" Type="16" Title="Copy of New Component" Modified="2010-06-13T11:51:25" IsNew="False" Icon="T16L0P1" />
	<tcm:Item ID="tcm:41-116" Type="16" Title="First Post" Modified="2005-06-13T15:06:53" IsNew="False" Icon="T16L0P1" />
</tcm:ListItems>

Note that all retrieved tcm:Item elements have the default set of attributes: ID, Type, Title, Modified, IsNew, and Icon.