Querying pages

Posted by Community Admin on 04-Aug-2018 16:09

Querying pages

All Replies

Posted by Community Admin on 17-Apr-2012 00:00

Hi,

I need to programmatically retrieve pages that match a certain url. I have the following code
but I want to get the page based on the url of the page, when I tried to use p.getFullUrl I get 
an error message saying that method is not implemented for querying the database

 IQueryable<PageNode> pagenodes = pageManager.GetPageNodes().Where(p => p.Parent != null && p.Parent.UrlName.ToString().ToLower() == "books");

Thanks,
Annie

Posted by Community Admin on 18-Apr-2012 00:00

Hello,

From what I understand, you want to get a page by its URL.
I would recommend two ways of doing this:

1:

PageManager pageManager = PageManager.GetManager();
PageNode pageNode = pageManager.GetPageNodes().Where(pN => pN.UrlName == "childofhome").FirstOrDefault();

2:

var page = SitefinitySiteMap.GetCurrentProvider().FindSiteMapNode("childofhome ");
PageNode pageNode = PageManager.GetManager().GetPageNodes().Where(p => p.Title == page.Title).First();

Page title is also a unique attribute for every page.
Both of the approaches above will return the corresponding node; if you want to extract the url of the node, use:
pageNode.GetUrl() or pageNode.GetFullUrl(). Example of the returned URL may look like: ~/home/childofhome/

I can also recommend you a reference from Sitefinity Documentation which describes querying pages:  http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/pages/querying-pages

If my response did not fully answer your question, do not hesitate to contact me again, and explain me in more details your case.

All the best,
Ivan
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed