Image Properties

Image Properties

Sitecore Image Fields Guidelines

  • Define the source field of Image fields to indicate the location in the Media Library that is relevant to the media item

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

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

Image Properties C# Web Control Code

//get Simple Fields metadata item from master 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.ImageField imgFld = item.Fields["example image"];
if (imgFld == 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}: {1}", "Field", imgFld.InnerField.DisplayName);
output.RenderEndTag(); //P

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

output.RenderEndTag(); //Div


Image Properties C# Web Control Output

Can Read? True
Can Write? True
Contains Standard Value? False
Definition: Example Image
Description: 
Display Name: Example Image
Has Blob Stream? False
Has Value? True
ID: {D1A29082-2D93-4A37-B32F-F2EB9DB27CBA}
Contains Inherited Value?
Is Blob Field? False
Has Been Modified? False
Key: example image
Language: en
Name: Example Image
Reset Blank On? False
Section Name: Simple Field Types
Sort Order: 500
Shared? False
Source: 
Title: 
Tooltip: 
Translatable? False
Type: Image
Type Key: image
Unversioned? False
Validation Regex: 
Validation Message: 
Value: