Get Root Items

Get Root Items

Root Items

  • The Sitecore root item 
  • The Content root item

Root Items C# Web Control Code

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

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

Sitecore.Data.Database db = Sitecore.Context.Database;
Sitecore.Data.Items.Item sitecoreRoot = db.GetRootItem();
if (sitecoreRoot != null)
    items.Add(sitecoreRoot);

Sitecore.Data.Items.Item contentRoot = db.GetItem(Sitecore.ItemIDs.ContentRoot);
if (contentRoot != null)
    items.Add(contentRoot);

Sitecore.Data.Items.Item branchesRoot = db.GetItem(Sitecore.ItemIDs.BranchesRoot);
if (branchesRoot != null)
    items.Add(branchesRoot);

Sitecore.Data.Items.Item devicesRoot = db.GetItem(Sitecore.ItemIDs.DevicesRoot);
if (devicesRoot != null)
    items.Add(devicesRoot);

Sitecore.Data.Items.Item languageRoot = db.GetItem(Sitecore.ItemIDs.LanguageRoot);
if (languageRoot != null)
    items.Add(languageRoot);

Sitecore.Data.Items.Item layoutRoot = db.GetItem(Sitecore.ItemIDs.LayoutRoot);
if (layoutRoot != null)
    items.Add(layoutRoot);

Sitecore.Data.Items.Item mediaLibRoot = db.GetItem(Sitecore.ItemIDs.MediaLibraryRoot);
if (mediaLibRoot != null)
    items.Add(mediaLibRoot);

Sitecore.Data.Items.Item placeholderSettingsRoot = db.GetItem(Sitecore.ItemIDs.PlaceholderSettingsRoot);
if (placeholderSettingsRoot != null)
    items.Add(placeholderSettingsRoot);

Sitecore.Data.Items.Item systemRoot = db.GetItem(Sitecore.ItemIDs.SystemRoot);
if (systemRoot != null)
    items.Add(systemRoot);

Sitecore.Data.Items.Item templateRoot = db.GetItem(Sitecore.ItemIDs.TemplateRoot);
if (templateRoot != null)
    items.Add(templateRoot);

Sitecore.Data.Items.Item workflowRoot = db.GetItem(Sitecore.ItemIDs.WorkflowRoot);
if (workflowRoot != null)
    items.Add(workflowRoot);

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);
//using &#58; for colon and &#160; for space
output.Write("{0}&#58;&#160;{1}", "Item", item.DisplayName);
output.RenderEndTag(); //P

output.Write("<br/>");
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Border, "0");
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Cellpadding, "3");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Table);
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Thead);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "left");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Th);
output.Write("Display Name");
output.RenderEndTag(); //Th
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "left");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Th);
output.Write("Template");
output.RenderEndTag(); //Th
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "left");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Th);
output.Write("Content Path");
output.RenderEndTag(); //Th
output.RenderEndTag(); //Thead
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Tbody);

foreach (Sitecore.Data.Items.Item child in items)
{
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Tr);
    output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "left");
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Td);
    output.Write("{0}", child.DisplayName);
    output.RenderEndTag(); //Td

    output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "left");
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Td);
    output.Write("{0}", child.TemplateName);
    output.RenderEndTag(); //Td

    output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "left");
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Td);
    output.Write("{0}", child.Paths.ContentPath);
    output.RenderEndTag(); //Td
    output.RenderEndTag(); //Tr
}
output.RenderEndTag(); //Tbody
output.RenderEndTag(); //Table
output.RenderEndTag(); //Div


Root Items C# Web Control Output

Display Name Template Content Path
sitecore Root /sitecore
Content Main section
Branches Branch Folder /sitecore/templates/Branches
Devices Node /sitecore/layout/Devices
Languages Node /sitecore/system/Languages
Layout Main section /sitecore/layout
Media Library Main section /sitecore/media library
Placeholder Settings Folder /sitecore/layout/Placeholder Settings
System Main section /sitecore/system
Templates Main section /sitecore/templates
Workflows Node /sitecore/system/Workflows