Check Field Types

Check Field Types

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Configuration.Factory
  • Sitecore.Collections.FieldCollection
  • Sitecore.Data.Database
  • Sitecore.Data.Fields.CheckboxField
  • Sitecore.Data.Fields.DateField
  • Sitecore.Data.Fields.Field
  • Sitecore.Data.Fields.FieldTypeManager
  • Sitecore.Data.Fields.FileField
  • Sitecore.Data.Fields.HtmlField
  • Sitecore.Data.Fields.ImageField
  • Sitecore.Data.Fields.LinkField
  • Sitecore.Data.Fields.LookupField
  • Sitecore.Data.Fields.MultilistField
  • Sitecore.Data.Fields.ReferenceField
  • Sitecore.Data.Fields.TextField
  • Sitecore.Data.Fields.WordDocumentField
  • Sitecore.Data.Items.Item

Check Field Types C# Web Control Code

//get Simple Fields metadata item from context database using item path
Sitecore.Data.Database db = Sitecore.Context.Database;
Sitecore.Data.Items.Item item = db.GetItem("/sitecore/content/TIC-Meta/FieldsDemos/Simple Fields");
if (item == null) return;

Sitecore.Collections.FieldCollection fields = item.Fields;
if (fields == null) return;
fields.ReadAll();

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "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);
string displayName = Sitecore.StringUtil.GetString(item.DisplayName, item.Name);
//using : for colon and   for space
output.Write("{0}: {1}", "Item", displayName);
output.RenderEndTag(); //P

foreach (Sitecore.Data.Fields.Field field in fields)
{
if (Sitecore.Data.Fields.FieldTypeManager.GetField(field) is Sitecore.Data.Fields.LinkField)
output.Write("{0}&#58;&#160;{1}", field.DisplayName, "<b>Internal, External, Media, Mailto, Anchor, or JavaScript Link</b><br/>");
else if (Sitecore.Data.Fields.FieldTypeManager.GetField(field) is Sitecore.Data.Fields.TextField)
output.Write("{0}&#58;&#160;{1}", field.DisplayName, "<b>Single-Line Text, Multi-Line Text, Number, or Password</b><br/>");
else if (Sitecore.Data.Fields.FieldTypeManager.GetField(field) is Sitecore.Data.Fields.HtmlField)
output.Write("{0}&#58;&#160;{1}", field.DisplayName, "<b>Rich Text Field</b><br/>");
else if (Sitecore.Data.Fields.FieldTypeManager.GetField(field) is Sitecore.Data.Fields.MultilistField)
output.Write("{0}&#58;&#160;{1}", field.DisplayName, "<b>Multilist, Checklist, Treelist, or Treelist-Ex</b><br/>");
else if (Sitecore.Data.Fields.FieldTypeManager.GetField(field) is Sitecore.Data.Fields.CheckboxField)
output.Write("{0}&#58;&#160;{1}", field.DisplayName, "<b>Checkbox</b><br/>");
else if (Sitecore.Data.Fields.FieldTypeManager.GetField(field) is Sitecore.Data.Fields.DateField)
output.Write("{0}&#58;&#160;{1}", field.DisplayName, "<b>Date or Datetime</b><br/>");
else if (Sitecore.Data.Fields.FieldTypeManager.GetField(field) is Sitecore.Data.Fields.FileField)
output.Write("{0}&#58;&#160;{1}", field.DisplayName, "<b>File</b><br/>");
else if (Sitecore.Data.Fields.FieldTypeManager.GetField(field) is Sitecore.Data.Fields.ImageField)
output.Write("{0}&#58;&#160;{1}", field.DisplayName, "<b>Image</b><br/>");
else if (Sitecore.Data.Fields.FieldTypeManager.GetField(field) is Sitecore.Data.Fields.LookupField)
output.Write("{0}&#58;&#160;{1}", field.DisplayName, "<b>Lookup</b><br/>");
else if (Sitecore.Data.Fields.FieldTypeManager.GetField(field) is Sitecore.Data.Fields.ReferenceField)
output.Write("{0}&#58;&#160;{1}", field.DisplayName, "<b>Droplink, Grouped Droplink, or Droptree</b><br/>");
else if (Sitecore.Data.Fields.FieldTypeManager.GetField(field) is Sitecore.Data.Fields.WordDocumentField)
output.Write("{0}&#58;&#160;{1}", field.DisplayName, "<b>Word Document</b><br/>");  
}
output.RenderEndTag(); //Div


Check Field Types C# Web Control Output

Archive Version date: Date or Datetime
Updated: Date or Datetime
Example Datetime: Date or Datetime
Subitems Sorting: Lookup
Help link: Internal, External, Media, Mailto, Anchor, or JavaScript Link
Archive date: Date or Datetime
Example Date: Date or Datetime
Reminder text: Single-Line Text, Multi-Line Text, Number, or Password
Publishing targets: Multilist, Checklist, Treelist, or Treelist-Ex
Workflow: Droplink, Grouped Droplink, or Droptree
Read Only: Checkbox
Created by: Single-Line Text, Multi-Line Text, Number, or Password
Short description: Single-Line Text, Multi-Line Text, Number, or Password
Validation Bar Validation Rules: Multilist, Checklist, Treelist, or Treelist-Ex
Thumbnail: Image
Hidden: Checkbox
Insert Options: Multilist, Checklist, Treelist, or Treelist-Ex
Example File: File
Long description: Single-Line Text, Multi-Line Text, Number, or Password
Suppressed Validation Rules: Single-Line Text, Multi-Line Text, Number, or Password
Example Image: Image
Style: Single-Line Text, Multi-Line Text, Number, or Password
Sortorder: Single-Line Text, Multi-Line Text, Number, or Password
Renderers: Single-Line Text, Multi-Line Text, Number, or Password
Editors: Multilist, Checklist, Treelist, or Treelist-Ex
Display name: Single-Line Text, Multi-Line Text, Number, or Password
Default workflow: Droplink, Grouped Droplink, or Droptree
Valid to: Date or Datetime
Unpublish: Date or Datetime
Updated by: Single-Line Text, Multi-Line Text, Number, or Password
__Originator: Droplink, Grouped Droplink, or Droptree
Publish: Date or Datetime
Lock: Single-Line Text, Multi-Line Text, Number, or Password
Controller: Single-Line Text, Multi-Line Text, Number, or Password
__Standard values: Droplink, Grouped Droplink, or Droptree
Revision: Single-Line Text, Multi-Line Text, Number, or Password
Skin: Single-Line Text, Multi-Line Text, Number, or Password
Reminder date: Date or Datetime
Created: Date or Datetime
Validation Button Validation Rules: Multilist, Checklist, Treelist, or Treelist-Ex
Owner: Single-Line Text, Multi-Line Text, Number, or Password
Quick Action Bar Validation Rules: Multilist, Checklist, Treelist, or Treelist-Ex
Hide version: Checkbox
Never publish: Checkbox
Insert Rules: Multilist, Checklist, Treelist, or Treelist-Ex
Valid from: Date or Datetime
Controller Action: Single-Line Text, Multi-Line Text, Number, or Password
State: Droplink, Grouped Droplink, or Droptree
Security: Single-Line Text, Multi-Line Text, Number, or Password
Example Rich Text: Rich Text Field
Reminder recipients: Single-Line Text, Multi-Line Text, Number, or Password
Workflow Validation Rules: Multilist, Checklist, Treelist, or Treelist-Ex
Example Word Document: Word Document
Context Menu: Droplink, Grouped Droplink, or Droptree
Example Multi-Line Text: Single-Line Text, Multi-Line Text, Number, or Password
Presets: Multilist, Checklist, Treelist, or Treelist-Ex
Example Checkbox: Checkbox
Example Single-Line Text: Single-Line Text, Multi-Line Text, Number, or Password
Ribbon: Droplink, Grouped Droplink, or Droptree