Sitecore – Display number of items in a folder

Problem: When working with folders, I often find it frustrating that I can’t see the number of items in that folder.  If there are a few, you can count, but if there are many it becomes a problem.  If there is a parent folder, it is as simple as looking into the parent folder to see the number of sub-items in the folder you are interested in.  That might not always be the case.

To resolve this, I thought it would be nice to show the count when you are viewing a folder.  Here is what I did with the help of Mr. Matt Hovany:

1. Open Folder.xaml.xml file in WebsitesitecoreshellApplicationsContent ManagerEditorsFolder folder.

2. Add a Literal right above the GridPanel as shown below:

    <Sitecore.Controls.HtmlPage runat="server">
      <Stylesheet runat="server" Src="Folder.css" DeviceDependant="true" x:placeholder="Stylesheets"/>
      <AjaxScriptManager runat="server"/>
      <ContinuationManager runat="server" />
      <div> <!-- Line Added -->
        <asp:Literal ID="TotalLit" runat="server" Visible="false"  /> <!-- Line Added -->
      </div> <!-- Line Added -->
      <GridPanel runat="server" Width="100%" Height="100%">
        <Scrollbox runat="server" ID="ItemList" Width="100%" Height="100%" Border="none" Padding="0px" Background="transparent" GridPanel.Height="100%" ContextMenu="FileList_ContextMenu" />

3. Create a new class similar to the one below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Sitecore.Shell.Applications.ContentEditor.Editors.Folder;
using Sitecore.Web.UI.XamlSharp.Xaml;
using Sitecore.Web;
using Sitecore.Data;
using Sitecore.Globalization;
using Sitecore.Data.Items;

namespace SitecoreCustomFolder
    public class CustomFolder : Sitecore.Shell.Applications.ContentEditor.Editors.Folder.FolderPage

        protected System.Web.UI.WebControls.Literal TotalLit;

        protected override void OnLoad(EventArgs e)

            if (!XamlControl.AjaxScriptManager.IsEvent)
                string queryString = WebUtil.GetQueryString("id");
                string name = WebUtil.GetQueryString("language");
                string databaseName = WebUtil.GetQueryString("database");
                ItemUri uri = new ItemUri(queryString, Language.Parse(name), Sitecore.Data.Version.Latest, databaseName);
                Item item = Database.GetItem(uri);

                if (item != null)
                    List<Item> items = this.GetItems(item);
                    if (items.Count != 0)
                        this.TotalLit.Text = "<div class="scTitle scTilesTitle">Items in Folder: " + items.Count.ToString() + " </div>";
                        this.TotalLit.Visible = true;

4. Modify the Folder.xaml.xml to reflect the new class on the inherits attribute:

<Sitecore.Shell.Applications.ContentEditor.Editors.Folder x:inherits="SitecoreCustomFolder.CustomFolder">

5. Here is the end result:

Tagged as: , , , , , , ,