Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Page URL using Sitefinity 4 Fluent API

Okay, this seems like a pretty simple thing to do. But I'm trying to use the Sitefinity 4 Fluent API to query for a page and populate the Text/NavigationUrl properties of a HyperLink. The text gets populated fine - but it has a hard time getting the Url from the page.

        PageNode page = App.WorkWith().Page(PageId).Get();
        PageLink.Text = page.Title;
        PageLink.NavigateUrl = page.Urls.Where<PageUrlData>(pU => pU.RedirectToDefault == false).FirstOrDefault<PageUrlData>().Url;

The first and second line work fine (PageLink.Text shows the page title). On the third line, I get an "Object reference not set to an instance of an object." error... FYI PageId is a Guid reference to a page.

Any help would be greatly appreciated.

like image 222
Avisra Avatar asked Feb 24 '23 03:02

Avisra


1 Answers

Found the issue. PageNode requires "Telerik.Sitefinity.Pages.Model" as a reference. I had that, but later found that you ALSO need to include "Telerik.Sitefinity.Modules.Pages".

This adds a new method to my belt which I've used below (getFullUrl):

    PageNode page = App.WorkWith().Page(PageId).Get();
    PageLink.Text = page.Title;
    PageLink.NavigateUrl = page.GetFullUrl();

Thanks

like image 116
Avisra Avatar answered Mar 08 '23 09:03

Avisra