Date Properties

Date Properties

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Database
  • Sitecore.Data.Fields.DateField
  • Sitecore.Data.Items.Item
  • Sitecore.MainUtil

Date Properties C# Web Control Code

//get Simple Fields metadata item from context database using item guid
Sitecore.Data.Database db = Sitecore.Context.Database;
Sitecore.Data.Items.Item item = db.GetItem("{EC44470F-FF45-4023-95C2-EC886FD33D0C}");
if (item == null) return;
Sitecore.Data.Fields.DateField dateFld = item.Fields["example date"];
if (dateFld == null) return;

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();

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

output.Write("Can Read? " + "<b>" + dateFld.InnerField.CanRead.ToString() + "</b><br/>"); 
output.Write("Can Write? " + "<b>" + dateFld.InnerField.CanWrite.ToString() + "</b><br/>"); 
output.Write("Contains Standard Value? " + "<b>" + dateFld.InnerField.ContainsStandardValue.ToString() + "</b><br/>"); 
output.Write("Definition: " + "<b>" + dateFld.InnerField.Definition.Name + "</b><br/>"); 
output.Write("Description: " + "<b>" + dateFld.InnerField.Description + "</b><br/>"); 
output.Write("Display Name: " + "<b>" + dateFld.InnerField.DisplayName + "</b><br/>"); 
output.Write("Has Blob Stream? " + "<b>" + dateFld.InnerField.HasBlobStream.ToString() + "</b><br/>"); 
output.Write("Has Value? " + "<b>" + dateFld.InnerField.HasValue.ToString() + "</b><br/>"); 
output.Write("ID: " + "<b>" + dateFld.InnerField.ID.ToString() + "</b><br/>"); 
output.Write("Contains Inherited Value? " + "<b>" + dateFld.InnerField.InheritedValue + "</b><br/>"); 
output.Write("Is Blob Field? " + "<b>" + dateFld.InnerField.IsBlobField.ToString() + "</b><br/>"); 
output.Write("Has Been Modified? " + "<b>" + dateFld.InnerField.IsModified.ToString() + "</b><br/>"); 
output.Write("Key: " + "<b>" + dateFld.InnerField.Key + "</b><br/>"); 
output.Write("Language: " + "<b>" + dateFld.InnerField.Language.Name + "</b><br/>"); 
output.Write("Name: " + "<b>" + dateFld.InnerField.Name + "</b><br/>"); 
output.Write("Reset Blank On? " + "<b>" + dateFld.InnerField.ResetBlank.ToString() + "</b><br/>"); 
output.Write("Section Name: " + "<b>" + dateFld.InnerField.Section + "</b><br/>"); 
output.Write("Sort Order: " + "<b>" + dateFld.InnerField.Sortorder.ToString() + "</b><br/>"); 
output.Write("Shared? " + "<b>" + dateFld.InnerField.Shared.ToString() + "</b><br/>"); 
output.Write("Source: " + "<b>" + dateFld.InnerField.Source + "</b><br/>"); 
output.Write("Title: " + "<b>" + dateFld.InnerField.Title + "</b><br/>"); 
output.Write("Tooltip: " + "<b>" + dateFld.InnerField.ToolTip + "</b><br/>"); 
output.Write("Translatable? " + "<b>" + dateFld.InnerField.Translatable.ToString() + "</b><br/>"); 
output.Write("Type: " + "<b>" + dateFld.InnerField.Type + "</b><br/>"); 
output.Write("Type Key: " + "<b>" + dateFld.InnerField.TypeKey + "</b><br/>"); 
output.Write("Unversioned? " + "<b>" + dateFld.InnerField.Unversioned.ToString() + "</b><br/>"); 
output.Write("Validation Regex: " + "<b>" + dateFld.InnerField.Validation + "</b><br/>"); 
output.Write("Validation Message: " + "<b>" + dateFld.InnerField.ValidationText + "</b><br/>"); 
output.Write("Value: " + "<b>" + dateFld.InnerField.Value + "</b>");

output.RenderEndTag(); //Div


Date Properties C# Web Control Output

Field: Example Date

Can Read? True
Can Write? True
Contains Standard Value? False
Definition: Example Date
Description: 
Display Name: Example Date
Has Blob Stream? False
Has Value? True
ID: {6818871D-B182-43CE-81CB-FEC21365B2FC}
Contains Inherited Value? 10/4/2013 3:15:21 PM
Is Blob Field? False
Has Been Modified? False
Key: example date
Language: en
Name: Example Date
Reset Blank On? False
Section Name: Simple Field Types
Sort Order: 200
Shared? False
Source: 
Title: 
Tooltip: 
Translatable? False
Type: Date
Type Key: date
Unversioned? False
Validation Regex: 
Validation Message: 
Value: 10/4/2013 3:15:21 PM