Locked Items Report

Locked Items Report

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Items.Item

Locked Items Report C# Web Control Code

Sitecore.Data.Items.Item item = this.GetItem();
if (item == null) return;

Sitecore.Data.Items.Item home = Sitecore.Context.Database.GetItem("/sitecore/content/Home");
if (home == null) return;

Sitecore.Data.Items.Item[] descendants = home.Axes.GetDescendants();
if (descendants == null) return;

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("C# Web Control Real-time Output");
output.RenderEndTag();

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
output.Write("{0}: {1}", "Item", item.DisplayName);
output.RenderEndTag(); //P
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
output.Write("{0}", "Currently Locked Items");
output.RenderEndTag(); //P

int i = 0;
foreach (Sitecore.Data.Items.Item descendant in descendants)
{
if (descendant.Locking.IsLocked())
{
i++;
output.Write("{0}", descendant.Paths.Path + "<br/>");
}
}
if (i == 0)
output.Write("{0}", "There are currently no items that are locked");

output.RenderEndTag(); //Div


Locked Items Report C# Web Control Output

Currently Locked Items

There are currently no items that are locked