November Happy Hour will be moved to Thursday December 5th.

Searching by URL segment

Vote:
 

Is it possible to use the URL segment property as a search criteria? The following code gives me the first page in the page tree, rather than the "About us" page, which is what I'm looking for. If I search by "PageName" though - using "About us" as the value - it works fine.

PropertyCriteria propertyCriteria1 = new PropertyCriteria();

propertyCriteria1.Condition = EPiServer.Filters.CompareCondition.Equal;

propertyCriteria1.Name = "PageURLSegment";

propertyCriteria1.Value = "About-us";

propertyCriteria1.Type = PropertyDataType.String;

propertyCriteria1.Required = true;

propertyCriteriaCollection.Add(propertyCriteria1);

PageDataCollection rootPageDataCollection = searchPages.FindPagesWithCriteria(PageReference.StartPage, propertyCriteriaCollection);

#22363
Aug 04, 2008 11:34
Vote:
 
If you're only after the "About us" page, you should use an EPiServer Propery to reference your page - using FindPagesWithCriteria will affect performance since it bypasses the cache.
#22367
Aug 04, 2008 12:47
Vote:
 

No, I'm not specifically after the "About us" page - I want to be able to find any page based on its URL segment property - e.g. by searching for "Contact-us" (as in www.website.com/Contact-us) I want to get the Page Reference for the "Contact us" page.

This seems to be a better way of doing it as it gives me a simple Integer list of IDs rather than a collection of PageData objects, but it still doesn't work properly for the URL segment property - searching for "About-us" gives me a list of every ID from the page tree when I'd expect it to return just a single ID as there's only one page with the URL segment "About-us" in my page tree:

PropertyCriteria propertyCriteria = new PropertyCriteria();

propertyCriteria.Condition = EPiServer.Filters.CompareCondition.Equal;

propertyCriteria.Name = "PageURLSegment";

propertyCriteria.Type = PropertyDataType.String;

propertyCriteria.Value = "About-us";

propertyCriteria.Required = true;

EPiServer.DataAccess.PropertySearchDB propertySearchDB = new EPiServer.DataAccess.PropertySearchDB();

System.Collections.Generic.IList<int> pageList = propertySearchDB.FindPagesWithSingleCriteria(PageReference.StartPage.ID, propertyCriteria,

new PageData(PageReference.StartPage).LanguageBranch);

 

 

 

#22373
Aug 04, 2008 18:28
* 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.