Database Names

Database Names

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • System.Collections.Generic.List
  • Sitecore.Configuration.Factory
  • Sitecore.Context
  • Sitecore.Data.Database
  • Sitecore.Data.Items.Item

Database Names C# Web Control Code

System.Collections.Generic.List<Sitecore.Data.Database> dbList = Sitecore.Configuration.Factory.GetDatabases();
Sitecore.Data.Items.Item item = Sitecore.Context.Item;
if (dbList == null || 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 &#58; for colon and &#160; for space
output.Write("{0}&#58;&#160;{1}", "Item", item.DisplayName);
output.RenderEndTag(); //P
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Ul);

if(dbList !=null)
{
    foreach(Sitecore.Data.Database db in dbList)
    {
        output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li);
        output.Write("{0}&#58;&#160;{1}", "Database Name", "<b>" + db.Name + "</b>");
        output.RenderEndTag(); //Li
    }
}
output.RenderEndTag(); //Ul
output.RenderEndTag(); //Div


Database Names C# Web Control Output

  • Database Name: core
  • Database Name: master
  • Database Name: web
  • Database Name: filesystem