Content Database

Content Database

Content Database

  • What the CMS user interface components interact with
  • The default is the Master database in the user interfaces
  • Is undefined for the managed web sites, Page Editor, and Preview
  • The Sitecore Desktop Taskbar can be used to select a different content database
  • Use the Sitecore.Context.ContentDatabase property to access the content database from the desktop or Content Editor

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Database

C# Web Control Code

<>output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Id, "snip-output-heading");
output.Write("C# Code Real-time Output");
output.RenderEndTag(); <>output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Id, "snip-output");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Ul); <>Sitecore.Data.Database db = Sitecore.Context.ContentDatabase;
string dbName = string.Empty;
if (db != null)
    dbName = db.Name;
    dbName = "Not defined in this context"; <>output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li);
output.Write("{0}{1}", "Content Database: ", dbName);
output.RenderEndTag(); //Li
output.RenderEndTag(); //Ul
output.RenderEndTag(); //Div 

C# Web Control Real-time Output

  • Content Database: Not defined in this context