List Devices

List Devices

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Configuration.Factory
  • Sitecore.Data.Database
  • Sitecore.Data.DeviceRecords
  • Sitecore.Data.Items.DeviceItem
  • Sitecore.Data.Items.Item
  • Sitecore.Resources.ResourceItems
  • System.Text.StringBuilder

List Devices C# Web Control Code

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

Sitecore.Data.Database db = Sitecore.Configuration.Factory.GetDatabase("master");
System.Text.StringBuilder builder = new System.Text.StringBuilder();

Sitecore.Resources.ResourceItems resources = db.Resources;
Sitecore.Data.DeviceRecords deviceRecords = resources.Devices;
builder.Append("Devices Root: <b>" + deviceRecords.BasePath + "</b><br/><br/>");

Sitecore.Data.Items.DeviceItem[] devices = deviceRecords.GetAll();
int i = 0;
foreach (var device in devices)
{
    i++;
    builder.Append("Display Name: <b>" + device.DisplayName + "</b><br/>");
    builder.Append("Agent Identification String: <b>" + device.Agent + "</b><br/>");
    builder.Append("Icon: <b>" + device.Icon + "</b><br/>");
    builder.Append("ID: <b>" + device.ID + "</b><br/>");
    builder.Append("Is Default? <b>" + device.IsDefault.ToString() + "</b><br/>");
    builder.Append("Is Valid? <b>" + device.IsValid.ToString() + "</b>");
    if (i < devices.Length) builder.Append("<hr/>");
}

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("{0}", "C# Web Control Real-time Output");
output.RenderEndTag(); //Div

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);
output.Write("{0}&#58;&#160;{1}", "Item", item.DisplayName);
output.RenderEndTag(); //P

output.Write("{0}", builder.ToString());

output.RenderEndTag(); //Div


List Devices C# Web Control Output

 

Devices Root: {E18F4BC6-46A2-4842-898B-B6613733F06F}

Display Name: Default
Agent Identification String: 
Icon: People/16x16/monitor.png
ID: {FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}
Is Default? True
Is Valid? False

 

 

Display Name: Print
Agent Identification String: 
Icon: /sitecore/shell/themes/standard/people/16x16/printer.png
ID: {46D2F427-4CE5-4E1F-BA10-EF3636F43534}
Is Default? False
Is Valid? False

 

 

Display Name: Feed
Agent Identification String: 
Icon: Custom/16x16/rss.png
ID: {73966209-F1B6-43CA-853A-F1DB1C9A654B}
Is Default? False
Is Valid? False