Query all pages in all sites

To get all published pages on all sites you first iterate all sites by using the MultiSiteContext.GetSites list. Then, for each site, you use the PageManager.GetNodes method and filter the pages in Published state.

Use the following code sample:

C#
using System.Collections.Generic;
using System.Linq;
using Telerik.Sitefinity.Modules.Pages;
using Telerik.Sitefinity.Multisite;
using Telerik.Sitefinity.Pages.Model;
using Telerik.Sitefinity.Services;

namespace SitefinityWebApp
{
    public class GetAllPagesFromAllSites
    {
        public static List<PageNode> GetAllPageNodes()
        {
            var multisiteContext = SystemManager.CurrentContext as MultisiteContext;
            var allSites = multisiteContext.GetSites().ToList();
            var allPageNodes = new List<PageNode>();
            foreach (var site in allSites)
            {
                PageManager pageManager = PageManager.GetManager();
                pageManager.Provider.SuppressSecurityChecks = true;
                var allPagesPerSite = pageManager.GetPageNodes().ToList().Where(x => x.RootNodeId == site.SiteMapRootNodeId && x.ApprovalWorkflowState == "Published" && !x.IsBackend && !x.IsDeleted);
                pageManager.Provider.SuppressSecurityChecks = false;
                foreach (var page in allPagesPerSite)
                {
                    if (page != null)
                        allPageNodes.Add(page);
                }
            }
            return allPageNodes;
        }
    }
}
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.
New to Sitefinity?