Get All Devices

Get All Devices

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Items.DeviceItem
  • Sitecore.Data.Items.Item
  • System.Linq

All Devices C# Web Control Code

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

Sitecore.Data.Items.DeviceItem[] deviceitems = Sitecore.Context.Database.Resources.Devices.GetAll();
if (deviceitems == 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

int iDevice = 0, iDeviceCount = deviceitems.Count();
foreach (Sitecore.Data.Items.DeviceItem deviceitem in deviceitems)
    output.Write("{0}&#58;&#160;{1}", "Device Name", "<b>" + deviceitem.Name + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Device Query String", "<b>" + deviceitem.QueryString + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Device Agent", "<b>" + deviceitem.Agent + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Device Icon", "<b>" + deviceitem.Icon + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Device is default?", "<b>" + deviceitem.IsDefault + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Device is valid?", "<b>" + deviceitem.IsValid + "</b><br/>");
    if (iDevice < iDeviceCount)
output.RenderEndTag(); //Div

All Devices C# Web Control Output

Device Name: Default
Device Query String: 
Device Agent: 
Device Icon: People/16x16/monitor.png
Device is default?: True
Device is valid?: False

Device Name: Print
Device Query String: p=1
Device Agent: 
Device Icon: /sitecore/shell/themes/standard/people/16x16/printer.png
Device is default?: False
Device is valid?: False

Device Name: Feed
Device Query String: rss=1
Device Agent: 
Device Icon: Custom/16x16/rss.png
Device is default?: False
Device is valid?: False


  • The Count() method uses System.Linq