Item Object Properties

Item Object Properties

Item Properties

  • item.Children contains child items using the Sitecore.Collections.ChildList class
  • item.Hidden controls whether Sitecore displays the item in the Content Tree
  • item.ID contains the GUID and is useful for comparing two items
  • item.Key contains the lowercase name of the item
  • item.Name contains the name of the item
  • item.Parent contains the name of the parent of the item
  • item.TemplateName contains the name of the data template that defines the item

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

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

Item Object Properties C# Web Control Code

Sitecore.Data.Items.Item item = Sitecore.Context.Item;
if (item == 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);
//using : for colon and ? for question mark and   for space
output.Write("{0}: {1}", "Item", item.DisplayName);
output.RenderEndTag(); //P

//using : for colon and ? for question mark and   for space
output.Write("{0}&#58;&#160;{1}", "Parent", "<b>" + item.Parent.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Parent ID", "<b>" + item.ParentID.ToString() + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Hidden", "<b>" + item.Appearance.Hidden.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Icon", "<b>" + item.Appearance.Icon + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Display Name", "<b>" + item.DisplayName + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Previous Sibling", "<b>" + item.Axes.GetPreviousSibling().Name + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Next Sibling", "<b>" + item.Axes.GetNextSibling().Name + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Has Children", "<b>" + item.HasChildren.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "ID", "<b>" + item.ID.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Key", "<b>" + item.Key + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Template Name", "<b>" + item.TemplateName + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Template ID", "<b>" + item.TemplateID.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "URI", "<b>" + item.Uri.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Creation Date", "<b>" + item.Statistics.Created.ToShortDateString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Created By", "<b>" + item.Statistics.CreatedBy + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Last Modified Date", "<b>" + item.Statistics.Updated.ToShortDateString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Last Modified By", "<b>" + item.Statistics.UpdatedBy + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Revision", "<b>" + item.Statistics.Revision + "</b>");
output.RenderEndTag(); //Div


Item Object Properties C# Web Control Output

Parent: Sitecore.Data.Items.Item
Parent ID: {D6187B4B-43B7-40E7-98B4-35DFF611272B}
Hidden? False
Icon: Software/32x32/text_code_colored.png
Display Name: Item Object Properties
Previous Sibling: InheritedTemplates
Next Sibling: ItemSettings
Has Children? False
ID: {221293C3-EEA5-4FA4-B278-26021DB9751B}
Key: itemobjectproperties
Template Name: TIC-CodeSnippet
Template ID: {B531AB47-F80F-4F35-B4FD-AA6AABB86017}
URI: sitecore://web/{221293C3-EEA5-4FA4-B278-26021DB9751B}?lang=en&ver=1
Creation Date: 9/5/2010
Created By: sitecore\craig
Last Modified Date: 10/2/2014
Last Modified By: extranet\Anonymous
Revision: 491fae4e-94fe-4c3a-98f4-4d198d0a1b5b

Sources