Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
You can programmatically search for Episerver CMS pages based on a certain page type. By specifying search criteria and a place to start the search you gets a PageDataCollection containing matching pages.
The DataFactory contains a method called FindPagesWithCriteria which takes a PageReference (representing where to start the search) and a PropertyCriteriaCollection object (representing what to search for). When the FindPagesWithCriteria method is called it returns a PageDataCollection object containing matching pages.
PropertyCriteriaCollection criterias = new PropertyCriteriaCollection();
Define the search criteria by creating a PropertyCriteria object that contains the information about the property criteria for the search:
PropertyCriteria criteria = new PropertyCriteria();
criteria.Condition = CompareCondition.Equal;
criteria.Name = "PageTypeID";
criteria.Type = PropertyDataType.PageType;
criteria.Value = Locate.ContentTypeRepository().Load("PageTypeNewsItem").ID.ToString();
criteria.Required = true;
Define another search criteria by creatihng a PropertyCriteria object tghat contains the information about the property criteria for the search:
PropertyCriteriaCollection criterias = new PropertyCriteriaCollection();
PropertyCriteria secCriteria = new PropertyCriteria();
secCriteria.Condition = EPiServer.Filters.CompareCondition.GreaterThan;
secCriteria.Name = "PageCreated";
secCriteria.Type = PropertyDataType.Date;
secCriteria.Value = DateTime.Now.AddDays(-120).ToString();
secCriteria.Required = true;
Add your specified criteria to the criteria collection as follows:
criterias.Add(criteria);
criterias.Add(secCriteria);
After you specify criteria, define where to start the search. Use the start page as the search starting point.
Note: The following example may return quite a few matches (and in some cases could be time-consuming).
PageDataCollection _newsPageItems = Locate.PageCriteriaQueryService().FindPagesWithCriteria(PageReference.StartPage, criterias);
Filter for visitors. The following filter removes pages that the current user does not have access to or that are not currently published:
FilterForVisitor.Filter(_newsPageItems);
new FilterSort(FilterSortOrder.PublishedDescending).Filter(_newsPageItems);
You can find the source code for the PageDataCollection and PageData classes the Framework Reference section under the Remarks section for the class.
Last updated: Sep 21, 2015