AI OnAI Off
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
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");
If I perform the search based on a different cirteria, I get the result I want, ie;
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.