Site Configuration

Site Configuration

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Configuration.Factory
  • Sitecore.Data.Items.Item
  • System.Xml.XmlDocument

C# Web Control Code

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

System.Xml.XmlDocument config = Sitecore.Configuration.Factory.GetConfiguration();
if (config == 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

output.Write("{0}&#58;&#160;{1}", "Name", "<b>" + config.Name + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Child Nodes Count", "<b>" + config.ChildNodes.Count.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Document Element Name", "<b>" + config.DocumentElement.Name + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "First Child", "<b>" + config.FirstChild.Name + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Has Child Nodes", "<b>" + config.HasChildNodes.ToString() + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Is ReadOnly", "<b>" + config.IsReadOnly.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Last Child", "<b>" + config.LastChild.Name + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Local Name", "<b>" + config.LocalName + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Node Type", "<b>" + config.NodeType.ToString() + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Preserve Whitespace", "<b>" + config.PreserveWhitespace.ToString() + "</b>");

output.RenderEndTag(); //Div

C# Web Control Real-time Output

Item: Site Configuration

Name: #document
Child Nodes Count: 1
Document Element Name: sitecore
First Child: sitecore
Has Child Nodes? True
Is ReadOnly? False
Last Child: sitecore
Local Name: #document
Node Type: Document
Preserve Whitespace? False