1

I have a folder, which has subfolders and components. Now i want to retrieve only the components which uses a specified schema.How do i do it using core services.

1 Answer 1

6

Try something like this:

using System.Xml.Linq;
using Tridion.ContentManager.CoreService.Client;            

...

            string folderUri = "";
            string schemaUri = "";

            OrganizationalItemItemsFilterData filter = new OrganizationalItemItemsFilterData();
            filter.ItemTypes = new ItemType[] { ItemType.Component };
            filter.ComponentTypes = new ComponentType[] { ComponentType.Normal };
            filter.Recursive = true;

            XElement items = Client.GetListXml(folderUri, filter);
            foreach (XElement item in items.Elements())
            {
                ComponentData component = Client.Read(item.Attribute("ID").Value, null) as ComponentData;

                if (component.Schema.IdRef.Equals(schemaUri))
                {

                    // Do something with components of specific schema 

                }

            }

Client variable is of type SessionAwareCoreServiceClient. You can find more detailed explanation of code above on blog http://codedweapon.com/2013/03/changing-components-schemas-with-core-service/

Something similar was already asked on post Get all component from selected folder and subfolder based on Schema

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.