1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / get all items from subcategories

get all items from subcategories

4 posts, 1 answered
  1. Rabindra
    Rabindra avatar
    106 posts
    Registered:
    17 May 2009
    10 Mar 2010
    Link to this post
    hi,
    In generic content module, I have created a category which has 5 subcategories. Each subcategory has some items.
    How do I retrieve all items from 5 subcategories?

    thanks
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    10 Mar 2010
    Link to this post
    Hi Rabindra,

    You can use GetContent(params IMetaSearchInfo[] filter) - Get filtered subset of content or ContentFilterBuilder class to get a list of filtered categorized content items.



    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Rabindra
    Rabindra avatar
    106 posts
    Registered:
    17 May 2009
    10 Mar 2010
    Link to this post
    Hi Ivan,
    I have tried that.
    My category name is Test and subcategories are Test1, test2, test3, test4, and test 5.
    When I view by category I see number 25 on the right hand side of the category. I beleive this is the total number of items of all subcategories. Each subcategory has 5 items.
    I used this code but doesn't return any items. (all items have not expired and are published) Please help.
                     Dim manager As ContentManager = New ContentManager
                Dim filter As New List(Of Telerik.Cms.Engine.IMetaSearchInfo)()
     
                filter.Add(New MetaSearchInfo(MetaValueTypes.ShortText, "Category", "Test"))
                filter.Add(New MetaSearchInfo(MetaValueTypes.DateTime, "Expiration_Date", DateTime.Now, SearchCondition.GreaterOrEqual))
     
                Dim listofItems As IList = manager.GetContent(0, 0, "Expiration_Date", Telerik.Cms.Engine.ContentStatus.Published, filter.ToArray())
     
                If listofItems.Count > 0 Then
                        '
                     End If
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    11 Mar 2010
    Link to this post
    Hi Rabindra,

    The code you use is not correct. You are not getting the tree of categories. You are passing only one category to the filter. You need to loop through the whole tree

    Here is the code you have use

    ContentManager nm = new ContentManager("Generic_Content");
    Guid categoryId = new Guid("40BAC027-433D-41EA-9439-6DFC1369DDF9");
    ICategory rootCategory = nm.GetCategory(categoryId);
    IList categoriesTree = nm.GetCategoriesTree(rootCategory);
    List<IMetaSearchInfo> filter = new List<IMetaSearchInfo>();
    foreach (ICategory c in categoriesTree)
    {
        filter.Add(new MetaSearchInfo(MetaValueTypes.ShortText, "Category", c.CategoryName));
    }
    IList cntItems = nm.GetContent(0, 0, "Expiration_Date ASC", filter.ToArray());



    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
    Answered
Register for webinar
4 posts, 1 answered