Query PageData by URL of the PageNode

Native API

To find a particular PageData by the URL of the PageNode, you use the GetPageNodes method and filter based on the UrlName property. Use the following code sample:

C#
using System.Linq;
using Telerik.Sitefinity.Modules.Pages;
using Telerik.Sitefinity.Pages.Model;

namespace SitefinityWebApp
{
    public class QueryPages_FindPagebyUrl_NativeAPI
    {
        public PageData FindPagebyUrlNativeAPI(string urlName)
        {
            PageManager pageManager = PageManager.GetManager();
            PageNode pageNode = pageManager.GetPageNodes().Where(pN => pN.UrlName == urlName).FirstOrDefault();

            if (pageNode == null)
            {
                return null;
            }

            return pageNode.GetPageData();
        }
    }
}

Fluent API

To find a particular PageData by the URL of the PageNode, you use the plural page facade to ensure that the PageNode with the specified UrlName exists. Then, you use the Get method of the plural page facade to get the PageNode. To get the PageData, you use the Page property in the following:

C#
using System.Linq;
using Telerik.Sitefinity;
using Telerik.Sitefinity.Pages.Model;

namespace SitefinityWebApp
{
    public class QueryPages_FindPagebyUrl_FluentAPI
    {
        public PageData FindPagebyUrlFluentAPI(string urlName)
        {
            PageData pageData = null;

            var count = 0;
            App.WorkWith().Pages().Where(pN => pN.UrlName == urlName).Count(out count);

            if (count != 0)
            {
                pageData = App.WorkWith().Pages().Where(pN => pN.UrlName == urlName).Get().First().Page;
            }

            return pageData;
        }
    }
}
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
This Article Contains
New to Sitefinity?