Get Devices

Get Devices


  • Logical representation of physical entity that makes HTTP requests
  • Describes attributes of the HTTP request
  • Contains presentation preferences for the HTTP response
  • Developers provide presentation layout details for each device that the page is expected to support
  • The context device is the device referenced by the current request
  • The Default device represents a Web browser
  • The Print device represents a page prepared to be sent to a printer
  • By default, the layout engine activates the Print device if the query string includes the parameter p with a value of 1 (p=1). If the layout engine does not activate the Print device, it activates the Default device.
  • Other devices include anything that can send an HTTP request and consume XML from the CMS, such as Braille devices, Web services, Flash, etc

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Database
  • Sitecore.Data.Items.DeviceItem
  • Sitecore.Data.Items.Item
  • Sitecore.Layouts.DeviceDefinition
  • Sitecore.Layouts.LayoutDefinition
  • System.Collections.ArrayList

C# Web Control Code

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

Sitecore.Data.Database db = Sitecore.Context.Database;
string renderings = Sitecore.Context.Item.Fields["__renderings"].Value;
Sitecore.Layouts.LayoutDefinition layout = Sitecore.Layouts.LayoutDefinition.Parse(renderings);
if (layout == null) return;

System.Collections.ArrayList devices = layout.Devices;
if (devices == null) return;

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.Write("C# Web Control Real-time Output");

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
//using : for colon and   for space
output.Write("{0}: {1}", "Item", item.DisplayName);
output.RenderEndTag(); //P

foreach (Sitecore.Layouts.DeviceDefinition device in devices)
    Sitecore.Data.Items.DeviceItem deviceItem = db.Resources.Devices[device.ID];
    output.Write("{0} - {1}", "<b>" + deviceItem.DisplayName + "</b>", device.ID.ToString() + "<br/>");

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
output.Write("Context Device");
output.RenderEndTag(); //P

output.Write("{0} - {1}", "<b>" + Sitecore.Context.GetDeviceName() + "</b>", Sitecore.Context.Device.ID.ToString());
output.RenderEndTag(); //Div


C# Web Control Real-time Output

Item: Devices

Default - {FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}
Print - {46D2F427-4CE5-4E1F-BA10-EF3636F43534}
Feed - {73966209-F1B6-43CA-853A-F1DB1C9A654B}

Context Device

Default - {FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}