Just wanted to post up a quick code snippet showing how to get a list of used items XML using the SDL Tridion 2011 core service. Why? Well previously the API typically used to work like itemType.GetListUsedItems() (where itemType is a Component or Page object etc), where as now the ‘Using’ and ‘Used’ items are read using a filter via the core service client method .GetListXML().
The example:
// Create a filter UsedItemsFilterData usingItemsFilterData = new UsedItemsFilterData { BaseColumns = ListBaseColumns.Id, // to specify the detail in the XML ItemTypes = new[] { ItemType.Folder, ItemType.Schema, ItemType } // to specify certain items }; // Get the XML by calling .GetListXml on the client (assumes you have a 'client' object already) XElement usingXML = client.GetListXml("tcm:4-283", usingItemsFilterData);If you’re looking to get the Using Items, for an item, you can simply use a UsingItemsFilterData filter in exactly the same way – enjoy
Nice code snippet. However, if you want the Pages that a Component is on, then we need to use UsingItemsFilterData instead of UsedItemsFilterData.
It’s worth noting that these are in the *Tridion.ContentManager.CoreService.Client* namespace (rather than having to reference the (internal) *Tridion.ContentManager.Data.dll*, as mentioned in the CHM documentation for the *UsedItemsFilterData* and *UsingItemsFilterData* classes.).