Search by language branch in EPiServer
This post is a complement to my previous post about searching pages with EPiServer. I have gotten a few questions about how to limit a page search to include pages from a specific language branch. Since this is truly a basic requirement when performing page searches, I'd like to share a simple way of accomplishing it:
1) Set up your criteria collection
See my previous post on searching with EPiServer for details regarding the PropertyCriteria object and the FindPagesWithCriteria method.
2) Add a language branch criteria
PropertyCriteria criteria = new PropertyCriteria();
criteria.Condition = EPiServer.Filters.CompareCondition.Equal;
criteria.Name = "PageLanguageID";
criteria.Type = PropertyDataType.String;
criteria.Value = "sv"; //Find swedish page versions
criteria.Required = true; //Criteria must be met
//Add the criteria to your PropertyCriteriaCollection
//object, here named 'criterias'
criterias.Add(criteria);
There you go, that's all you need to add a language branch condition for your page search!
Don't forget the search post for details on how to implement the page search using FindPagesWithCriteria.
Update: As Per points out, you may use one of the FindPagesWithCriteria overloads to specify the language branch directly in the method call.
02 March 2008