Looking for a sample TOM .NET code how to get all the components of a bundle and then process each component one by one as per their metadata value. Any pointers here , thanks
2 Answers
A bundle is an OrganizationalItem just like a folder or a structure group. You can get the items in the bundle with the GetListItems() method. If you only want to get components, you can use a filter like this:
// session can be obtained from any Tridion object (e.g. a component, page, etc)
var bundle = session.GetObject("tcm:3-123-2") as Bundle;
var filter = new OrganizationalItemItemsFilter(session)
{
ItemTypes = new[] { ItemType.Component }
};
var items = bundle.GetListItems(filter);
Besides all Q mentioned, you don't even need to use filter. Bundle has all IDs in source:
<Bundle xmlns="http://www.sdltridion.com/ContentManager/Bundle">
<Items xmlns="http://www.sdltridion.com/ContentManager/Bundle">
<Item xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="tcm:1-2123" xlink:title="title333"></Item>
<Item xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="tcm:1-3543" xlink:title="Page details"></Item>
<Item xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="tcm:1-3453" xlink:title="Battery"></Item>
<Item xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="tcm:1-34325" xlink:title="Download"></Item>
<Item xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="tcm:1-345" xlink:title="title2"></Item>
</Items>
So all you need is just extract IDs from the source using LINQ. One less call to Core service.