Querying pages
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
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.