0
votes

I would like to get a count of pages in nodes in an Umbraco site with output something like this:

  • Root (9 subnodes)
    • First Folder (4 subnodes)
      • document 1
      • document 2
      • document 3
      • document 4
    • Second Folder (3 subnodes)
      • document 1
      • document 2
      • document 3

Basically I am trying to see how much active content there is in a given site and come up with a way to divide the work. Is there a reasonable way to get this information?

1
"Active" as in Published?Morten OC
Yes. Published content.ericdc

1 Answers

1
votes

This worked for me:

  • Descendants.cs in App_Code folder

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using umbraco.presentation;
    using umbraco.presentation.nodeFactory;
    
    public static class ExtensionMethods
    {
        public static IEnumerable<Node> AllDescendants(this Node node)
        {
            foreach (Node child in node.Children)
            {
                yield return child;
    
                foreach (Node grandChild in child.AllDescendants())
                    yield return grandChild;
            }
        }
    }
    
  • Razor View

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using umbraco.presentation.nodeFactory;
    @{
       Layout = "";
    }
    
    @functions{
       public string CreateSitemap()
       {
            var temp = "<ul class='collapsibleList'>" + sitemap(-1) + "</ul>" + Environment.NewLine;
           return temp;
       }
    
    public string sitemap(int nodeID)
    {
        var rootNode = new umbraco.presentation.nodeFactory.Node(nodeID);
        var sitemapstring = "<li>" + rootNode.Name + " (" + rootNode.AllDescendants().Count() + ") <span style='font-size:9px'>" + rootNode.NodeTypeAlias + "</span></li>" + Environment.NewLine;
    
    if (rootNode.Children.Count > 0)
    {
        sitemapstring += "<ul>" + Environment.NewLine;
        sitemapstring = rootNode.Children.Cast<Node>().Aggregate(sitemapstring, (current, node) => current + sitemap(node.Id));
        sitemapstring += "</ul>" + Environment.NewLine;
    }
    return sitemapstring;
    }
    }
    <body>
     @Html.Raw(CreateSitemap())
    </body>