Field Properties

Field Properties

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Collections.FieldCollection
  • Sitecore.Context
  • Sitecore.Data.Fields.Field
  • Sitecore.Data.Items.Item
  • Sitecore.Web.UI.WebControls.FieldRenderer
  • System.Linq

Field Properties C# Web Control Code

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

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

var sortedList = (from entry in fields orderby entry.Name ascending select entry);

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("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);
//using : for colon and ? for question mark and   for space
output.Write("{0}: {1}", "Item", item.DisplayName);
output.RenderEndTag(); //P

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
output.Write("{0}", "Displaying first ten fields");
output.RenderEndTag(); //P

int i = 0;
foreach(Sitecore.Data.Fields.Field field in sortedList)
{
    i++;
    output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
    output.Write("{0}", field.DisplayName);
    output.RenderEndTag(); //P
    string fieldValue = string.Empty;

    if (field.Type == "Image")
        fieldValue = Sitecore.Web.UI.WebControls.FieldRenderer.Render(item,field.Name, "mh=50");
    else
        fieldValue = field.Value;

    output.Write("{0}&#58;&#160;{1}", "Name", "<b>" + field.Name + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Title", "<b>" + field.Title + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Value", "<b>" + fieldValue.ToString() + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Type", "<b>" + field.Type + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Section", "<b>" + field.Section + "</b><br/>");
    output.Write("{0}&#63;&#160;{1}", "Is Blob", "<b>" + field.IsBlobField.ToString() + "</b><br/>");
    output.Write("{0}&#63;&#160;{1}", "Can be read", "<b>" + field.CanRead.ToString() + "</b><br/>");
    output.Write("{0}&#63;&#160;{1}", "Can write to", "<b>" + field.CanWrite.ToString() + "</b><br/>");
    output.Write("{0}&#63;&#160;{1}", "Has a value", "<b>" + field.HasValue.ToString() + "</b><br/>");
    output.Write("{0}&#63;&#160;{1}", "Has been modified", "<b>" + field.IsModified.ToString() + "</b><br/>");
    output.Write("{0}&#63;&#160;{1}", "Is shared", "<b>" + field.Shared.ToString() + "</b><br/>");
    output.Write("{0}&#63;&#160;{1}", "Reset Blank", "<b>" + field.ResetBlank.ToString() + "</b><br/>");
    output.Write("{0}&#63;&#160;{1}", "Standard Value setting", "<b>" + field.ContainsStandardValue.ToString() + "</b><br/>");
    output.Write("{0}&#63;&#160;{1}", "Is translatable", "<b>" + field.Translatable.ToString() + "</b><br/>");
    output.Write("{0}&#63;&#160;{1}", "Is unversioned", "<b>" + field.Unversioned.ToString() + "</b>");
    if (i >= 10) break;
}

output.RenderEndTag(); //Div


Field Properties C# Web Control Output

Displaying first ten fields

Archive date

Name: __Archive date
Title: Archive date
Value: 
Type: datetime
Section: Tasks
Is Blob? False
Can be read? True
Can write to? True
Has a value? False
Has been modified? False
Is shared? True
Reset Blank? False
Standard Value setting? False
Is translatable? False
Is unversioned? False

Archive Version date

Name: __Archive Version date
Title: Archive Version date
Value: 
Type: Datetime
Section: Tasks
Is Blob? False
Can be read? True
Can write to? True
Has a value? False
Has been modified? False
Is shared? False
Reset Blank? False
Standard Value setting? False
Is translatable? False
Is unversioned? False

Context Menu

Name: __Context Menu
Title: Context Menu
Value: 
Type: tree
Section: Appearance
Is Blob? False
Can be read? True
Can write to? True
Has a value? False
Has been modified? False
Is shared? True
Reset Blank? False
Standard Value setting? False
Is translatable? False
Is unversioned? False

Controller

Name: __Controller
Title: Controller
Value: 
Type: text
Section: Layout
Is Blob? False
Can be read? True
Can write to? True
Has a value? False
Has been modified? False
Is shared? True
Reset Blank? False
Standard Value setting? False
Is translatable? True
Is unversioned? False

Controller Action

Name: __Controller Action
Title: Controller Action
Value: 
Type: text
Section: Layout
Is Blob? False
Can be read? True
Can write to? True
Has a value? False
Has been modified? False
Is shared? True
Reset Blank? False
Standard Value setting? False
Is translatable? True
Is unversioned? False

Created

Name: __Created
Title: Created
Value: 20110103T103118
Type: datetime
Section: Statistics
Is Blob? False
Can be read? True
Can write to? True
Has a value? True
Has been modified? False
Is shared? False
Reset Blank? False
Standard Value setting? False
Is translatable? False
Is unversioned? False

Created by

Name: __Created by
Title: Created by
Value: sitecore\craig
Type: text
Section: Statistics
Is Blob? False
Can be read? True
Can write to? True
Has a value? True
Has been modified? False
Is shared? False
Reset Blank? False
Standard Value setting? False
Is translatable? True
Is unversioned? False

Default workflow

Name: __Default workflow
Title: Default workflow
Value: {A958495A-A8B3-4570-85B4-EE2E4CCF9C71}
Type: reference
Section: Workflow
Is Blob? False
Can be read? True
Can write to? True
Has a value? False
Has been modified? False
Is shared? True
Reset Blank? False
Standard Value setting? False
Is translatable? False
Is unversioned? False

Display name

Name: __Display name
Title: Display name
Value: Field Properties
Type: text
Section: Appearance
Is Blob? False
Can be read? True
Can write to? True
Has a value? True
Has been modified? False
Is shared? False
Reset Blank? False
Standard Value setting? False
Is translatable? True
Is unversioned? True

Editor

Name: __Editor
Title: Editor
Value: 
Type: server file
Section: Appearance
Is Blob? False
Can be read? True
Can write to? True
Has a value? False
Has been modified? False
Is shared? True
Reset Blank? False
Standard Value setting? False
Is translatable? False
Is unversioned? False