Here are a few ways to retrieve data for a given page (expressed in a PageReference instance) in EPiServer:
PageReference pageref = ...; PageData pagedata; // In a page (which is a sub-class of PageBase, e.g. TemplatePage, EditPage, SimplePage) pagedata = this.Getpage(pageref); // In a user control (which is a sub-class of UserControlBase) pagedata = this.Getpage(pageref); // Anywhere pagedata = Global.EPDataFactory.GetPage(pageref);
Global.EPDataFactory also has some other useful functions:
// Open a page from a given FriendlyUrl rather than a PageReference // (which requires knowing the Page ID) pagedata = Global.EPDataFactory.GetPageByURL("/Bokningsbara-kurser/");
BTW, it’s also possible to initialize a PageReference with a Url (although NOT a Friendly Url):
pageref = PageReference.ParseUrl("http://localhost:8889/shop/Puff.aspx?id=130");
UPDATE (2007-06-04):
If you have a so called “simple address” such as “/foo”, then none of the above will work. In that case you have to use code such as this:
PropertyCriteriaCollection critcol = new PropertyCriteriaCollection(); PropertyCriteria crit = new PropertyCriteria(); crit.Condition = EPiServer.Filters.CompareCondition.Equal; crit.Name = "PageExternalURL"; crit.Type = PropertyDataType.String; crit.Value = simple_address.Trim(new char[] { '/' }); // Remove initial "/" critcol.Add(crit); PageDataCollection pagecol = Global.EPDataFactory.FindPagesWithCriteria(Global.EPConfig.RootPage, critcol); if (pagecol.Count > 0) { return pagecol[0].LinkURL; }
Hi! I see this is an old post but I wanna do this: pagedata = Global.EPDataFactory.GetPageByURL(“/Bokningsbara-kurser/”); in CMS6 but ‘EPiServer.DataFactory’ does not contain a definition for ‘GetPageByURL’
How to do this in CMS6?
//Johan
@Johan
Hi ,
I’m trying to migrate our app to EPiServer 5 and i’m also facing the same issue..did you get any alternative for GetPageByURL?
I’m really sorry for a very late reply to this, but I rarely work with EPiServer these days so I don’t know the answer to your question. If I come across it, I’ll post it here…
/Emil