I have a folder, which has subfolders and components.

For example, Main folder name as 030 Main, which has subfolders with names:

  • 100 mango
  • 120 apple
  • 150 cake
  • archive
  • not used
  • trash

There are also some components within 030 Main.

Now I want to retrieve only the components which uses a specified schema from certain subfolders (in bold above):

  • 100 mango
  • 120 apple
  • 150 cake

I don't need any components from archive,not used,or trash nor the components within 030 Main.

I tried something like below, first with a filter on the folder structure (I got tcm id's of archive,not used,100 mango,120 apple,150 cake,and trash).

Then I checked if the folder's tcm id matches 100 mango, 120 apple, or 150 cake.

If this condition is true, I use a component filter to get all the components with specified schema.

But here in var id I'm still getting the components present in archive, not used ,trash.

Please suggest may be the second filtering part is not working.

OrganizationalItemItemsFilterData filter = new OrganizationalItemItemsFilterData
                ItemTypes = new[] { ItemType.Folder },
              Recursive = true,
                BaseColumns = ListBaseColumns.Id

        foreach (var id in client.GetListXml(folderUri, filter).Elements().ToList())
            string so = id.Attribute("ID").Value;
           if ((so == "tcm:229-38695-2") || (so == "tcm:229-149861-2")||(so == "tcm:229-149940-2")||(so =="tcm:229-149941-2")||(so == "tcm:229-149942-2")||(so =="tcm:229-149943-2")||(so =="tcm:229-149875-2"))
                Console.WriteLine("i m in");
                OrganizationalItemItemsFilterData filter1 = new OrganizationalItemItemsFilterData();
                filter1.ItemTypes = new ItemType[] { ItemType.Component };
                filter1.ComponentTypes = new ComponentType[] { ComponentType.Normal };
                filter1.Recursive = true;

                StringBuilder sb = new StringBuilder();
                string QuestionTitle = string.Empty;
                foreach (var idin in client.GetListXml(folderUri, filter1).Elements().ToList())
                    string compSchema = idin.Attribute("SchemaId").Value;
                    string compId = idin.Attribute("ID").Value;

2 Answers 2


The line on code - var idin in client.GetListXml(folderUri, filter1)looks incorrect as it should be var idin in client.GetListXml(so, filter1) in my opinion to make any sense to your if clause

  • Also it seems the OR condition is put for all subfolders though the components have to be accessed from only three of them(guessing from number of checks).
    – Ashutosh
    Commented Dec 28, 2015 at 15:07
  • Pankaj Thanks, it works. And thanks everyone for your valuable time. Commented Dec 29, 2015 at 6:00
  • If it works, would you mind accepting it as an answer for the betterment of the website. Also, it would be great if you think the answer is good for an upvote Commented Dec 29, 2015 at 6:35

I would suggest to use a different approach with the Search Query API from the Core Service. Eric Huiza has written an excellent post about an example retrieving Components using a specific Schema. http://erichuiza.blogspot.bg/2012/06/performing-search-queries-with-core.html

In addition, it is possible to pass in a 'SearchIn' parameter as specified in this answer, Search in multiple folders via core service?

Overall this code should perform faster and also be more flexible. You might still need to apply a post-search filter, as in your code above, if you're not able to filter everything by the search query.

Your Answer

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

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