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; }