FindPagesWithCriteria doesn't return any hits for property "PageExternalURL"

Member since: 2006
 
I'm trying to find the page reference for a page based on above mentioned property,
but the search returns no hits. Below is the code I use;
PropertyCriteriaCollection criterias = new PropertyCriteriaCollection();

PropertyCriteria criteria = new PropertyCriteria();
criteria.Condition = EPiServer.Filters.CompareCondition.Equal;
criteria.Name = "PageExternalURL";
criteria.Type = PropertyDataType.String;
criteria.Value = "home";
criterias.Add(criteria);

PropertySearchDB search = new PropertySearchDB();
IList pageRefColl = search.FindPagesWithCriteria(PageReference.RootPage.ID, criterias, "en-GB");

PropertyCriteriaCollection criterias = new PropertyCriteriaCollection();

PropertyCriteria criteria = new PropertyCriteria();
criteria.Condition = EPiServer.Filters.CompareCondition.Equal;
criteria.Name = "PageExternalURL";
criteria.Type = PropertyDataType.String;
criteria.Value = "home";
criterias.Add(criteria);

PropertySearchDB search = new PropertySearchDB();
IList pageRefColl = search.FindPagesWithCriteria(PageReference.RootPage.ID, criterias, "en-GB");

If I perform the search based on a different cirteria, I get the result I want, ie;

PropertyCriteria criteria = new PropertyCriteria();
criteria.Condition = EPiServer.Filters.CompareCondition.Equal;
criteria.Name = "PageName";
criteria.Type = PropertyDataType.String;
criteria.Value = "Start";
criterias.Add(criteria);

 

The page is called "Start", its simple address is "home", and the language branch is "en-GB". What gives?

What I really want to do is to have an easy way to find a page from anywhere in the code-behind,
and I thought the simple address (or PageExternalURL) would be nice to use since it is unique,
and I have read that having to many dynamic porperties is not a good solution (performance wise).
I don't want to store the page id in some configuration file either,
as don't really want to have to administer/keep track of those ids
for the different environments we have (dev/int. test/ext. test/prod/ref).
If anyone has a better suggestion to do it, I'm all ears,
although I would also like to know why the above doesn't work.

#27869 Feb 11, 2009 11:59
  • Member since: 1996
     

    Hi Joakim!

    If you take a look at the column "ExternalURL" in the table tblPageLanguage (which is where the PageExternalURL is stored) you'll see that the actual value is prefixed with "~/".

    Now, as FindPagesWithCriteria works by building and executing directly towards the database, you would have to prefix the query value for "home" with "~/" so it becomes "~/home".

    Something like this:

    ...

    criteria.Value = "~/home";

    ...

     You'd think that you could also use CompareConditiion.EndsWith rather than Equal, but then there is the slight chance of you hitting the wrong pages as other pages ExternalURL may end with the same string..

    /johan 

    #27874 Feb 11, 2009 13:54
  • Member since: 2006
     
    That works, thanks a lot Johan. Didn't think about looking in the db, as the value you get when you retrieve it using page.Property["PageExternalURL"] isn't prefixed "~/" (although it is always in lower case even if you used upper case chars, so I should've known that something else could have been stripped from it as well).
    #27875 Feb 11, 2009 14:07
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
Please login to post a reply