Try our conversational search powered by Generative AI!

How to filter block by category using propertycriteria


Hi All, 

I am new to the episerver CMS. I have got the list of pages associated with a category using property criteria. Like that I need to list all the blocks in a site by a particular category, Is there any options available to do this using criteria or any builtin methods available. 

Here I have attached the code i did for filtering the pages by category.

PropertyCriteriaCollection criterias = new PropertyCriteriaCollection();
PropertyCriteria criteria = new PropertyCriteria();
criteria.Condition = CompareCondition.Equal;
criteria.Name = "PageTypeID";
criteria.Type = PropertyDataType.Category;
criteria.Value = "Sublevel1";
criteria.Required = true;
PageDataCollection pageList = Locate.PageCriteriaQueryService().FindPagesWithCriteria(PageReference.RootPage, criterias);

In the pageList i got all the pages with the category "Sublevel1", How to modify this code to get blocks ? 

Can anyone help me.

Thanks in advance.

Dec 11, 2015 7:47

Hi Dharani!

What you can do is to get all the blocks using contentRepository like described in this thread

You can use your block base page as the type to filter by or Episerver's if you don't have any.

Then using LINQ on the result collection you can filter to get those that have the "Sublevel1" category that you need.

Hope it helps!


Dec 16, 2015 15:45
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.