your link to better business solutions

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 \Website\sitecore\shell\Applications\Content Manager\Editors\Folder 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" />
      </GridPanel>
    </Sitecore.Controls.HtmlPage>

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)
        {
            base.OnLoad(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:

Share

Tagged as: , , , , , , ,

1 Responses »

  1. Hi Akshay,

    I was trying to implement a google sync operation and implemented something similar but some how
    if (!XamlControl.AjaxScriptManager.IsEvent)

    throws a AjaxScriptManager is null exception any hints.

    Line 24: base.OnLoad(e);
    Line 25:
    Line 26: if (!XamlControl.AjaxScriptManager.IsEvent)
    Line 27: {
    Line 28: ID id = new ID(Sitecore.Context.Request.QueryString["id"]);

    Source File: e:\TrainCore-Project_v1.1\BAWorks.Web.UI.HtmlControls\GoogleSyncModalDialogPage.cs Line: 26

    Stack Trace:

    [InvalidOperationException: AjaxScriptManager is null]
    Sitecore.Web.UI.XamlSharp.Xaml.XamlControl.get_AjaxScriptManager() +105
    BAWorks.Controls.GoogleSyncModalDialogPage.OnLoad(EventArgs e) in e:\TrainCore-Project_v1.1\BAWorks.Web.UI.HtmlControls\GoogleSyncModalDialogPage.cs:26
    System.Web.UI.Control.LoadRecursive() +71
    System.Web.UI.Control.LoadRecursive() +190
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStag

Leave a Response

Please note: comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.