Get Site Names

Get Site Names

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Configuration.Factory
  • Sitecore.Data.Items.Item
  • Sitecore.StringUtil

Site Names C# Web Control Code

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

string[] sites = Sitecore.Configuration.Factory.GetSiteNames();
if (sites == 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);
string displayName = Sitecore.StringUtil.GetString(item.DisplayName, item.Name);
//using : for colon and ? for question mark and   for space
output.Write("{0}: {1}", "Item", displayName);
output.RenderEndTag(); //P
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Ul);

foreach(string site in sites)
{
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li);
output.Write("{0}", site);
output.RenderEndTag(); //Li
}

output.RenderEndTag(); //Ul
output.RenderEndTag(); //Div


Site Names C# Web Control Output

  • shell
  • login
  • admin
  • service
  • modules_shell
  • modules_website
  • website
  • scheduler
  • system
  • publisher