I've been working with the Core Service recently, mainly to provide editors with lists of items (Components / Pages / Structure Groups) that have specific fields set or absent.
I can do all of this just fine, but the way I seem to be having to do this is a little clunky and the filters seem a little "hit and miss". What I'm trying to do in this example is to find all components that have a field "owner" set:
OrganizationalItemItemsFilterData filter = new OrganizationalItemItemsFilterData
{
ItemTypes = new [] {
ItemType.Component
},
ComponentTypes = new[] {
ComponentType.Normal
},
Recursive = true
};
XElement componentsXml = service.GetListXml(folder, filter);
The first issue is that what's returned from the service does contain Multimedia components, which is an issue when coming to read their metadata later on.
Am I using the wrong type of filter? I would have preferred to to have retrieved an Object rather than XML, but the GetList() method again complained about the type of filter and the only one I could find that worked did not have the necessary fields to populate (though I seem to remember reading that this was a known issue in 2011).
Then, later, I'm reading each individual Component after converting to an XmlDocument (I have a front end history, so my Linq-fu is pretty non-existent).
foreach (XmlNode node in nodes)
{
Console.Write("\rReading component: " + i + "/" + nodes.Count + " (" + (Math.Round((100D * i / nodes.Count)).ToString()) + "%): " + node.Attributes["ID"].Value + " " + node.Attributes["Title"].Value + " ");
try
{
components.Add((ComponentData)service.Read(node.Attributes["ID"].Value, new ReadOptions()));
}
catch
{
Console.WriteLine("Could not read Component" + node.Attributes["ID"].Value + "(" + node.Attributes["Title"].Value + ") - no longer exists?");
}
i++;
}
...and then running through the metadata to output values to a file:
Again, this all works, but it seems a quite inefficient.
Is there a method I haven't yet found that does most of the above in one hit, i.e. I give it a list of TCM URIs and it grabs be back data, rather than having to read them all individually?
Component
object using theGetList
method or in the form of XMLs usingGetListXml
method, and once you have this, you may need to filter out for Multimedia components - by checking for the Multimedia field in the component as well as for the field value.