1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Querying pages

Querying pages

2 posts, 0 answered
  1. Annie
    Annie avatar
    46 posts
    Registered:
    11 Aug 2012
    17 Apr 2012
    Link to this post
    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
  2. Ivan Eftimov
    Ivan Eftimov avatar
    23 posts
    Registered:
    08 Feb 2017
    18 Apr 2012
    Link to this post
    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
2 posts, 0 answered