Duplicate Names

Duplicate Names

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Items.Item
  • System.Collections.Generic.List

Duplicate Names C# Web Control Code

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

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

System.Collections.Generic.List<Sitecore.Data.Items.Item> children = new System.Collections.Generic.List<Sitecore.Data.Items.Item>();

var items = home.Axes.GetDescendants(); 
var dupNames = from item in items 
join item2 in items on item.Name equals item2.Name
where item.ID != item2.ID && item.HasChildren == false && item2.HasChildren == false
orderby item.Name ascending
select item;

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}&#58;&#160;{1}", "Item", context.DisplayName);
output.RenderEndTag(); //P

foreach (Sitecore.Data.Items.Item item in dupNames)
{
if (!children.Contains(item))
{
children.Add(item);
output.Write("{0}", item.Paths.Path + "<br/>");
}
}
output.RenderEndTag(); //Div


Duplicate Names C# Web Control Output

/sitecore/content/Home/PageNotFound
/sitecore/content/Home/WebDesigners/HTMLSupport/PageErrors/PageNotFound
/sitecore/content/Home/ContentAuthors/BuildingSites/SitecoreResources/SharedSource
/sitecore/content/Home/SiteDirectory/Information/Licenses/SharedSource
/sitecore/content/Home/ContentAuthors/Content/ItemLocks/UnlockingItems
/sitecore/content/Home/Developers/ContentDisplay/ItemLocking/UnlockingItems
/sitecore/content/Home/ProjectLeads/InfoArchitecture/SitecoreWorkflows/WorkflowStates
/sitecore/content/Home/Developers/ContentPromotion/ManagingWorkflow/WorkflowStates

Notes

  • Warning - This code could take a long time to complete for a large site