Return to doc.sitecore.com

Valid for Sitecore 5.3.1
7.  Image
Prev Next

The complex field type, Image stores it raw value as text:

  <image alt="Alternate text" width="150" height="150" hspace="4"
    vspace="4" mediaid="{539587C7-1F36-4D94-A10D-FFFAF079B746}"
    mediapath="/images/hist_gunung100px jpg" showineditor="1"
    usethumbnail="1" src="/upload/images/hist_gunung100px.jpg"/>

Resolve the value by using implicit casting

public static string outImage(Sitecore.Data.Items.Item item, string sFieldName)
{
  System.Text.StringBuilder builder
= new System.Text.StringBuilder();
  Sitecore.Data.Fields.ImageField imageField
= item.Fields[sFieldName];
  builder.Append(
"imageField.Alt = " + imageField.Alt);
  builder.Append(
"<br />");
  builder.Append(
"imageField.Class = " + imageField.Class);
  builder.Append(
"<br />");
  builder.Append(
"imageField.Height = " + imageField.Height);
  builder.Append(
"<br />");
  builder.Append(
"imageField.HSpace = " + imageField.HSpace);
  builder.Append(
"<br />");
  builder.Append(
"imageField.InternalPath = " + imageField.InternalPath);
  builder.Append(
"<br />");
  builder.Append(
"imageField.IsInternal.ToString() = " + imageField.IsInternal.ToString());
  builder.Append(
"<br />");
  builder.Append(
"imageField.LinkType = " + imageField.LinkType);
  builder.Append(
"<br />");
  builder.Append(
"imageField.MediaID = " + imageField.MediaID);
  builder.Append(
"<br />");
  builder.Append(
"imageField.MediaItem.DisplayName = " + imageField.MediaItem.DisplayName);
  builder.Append(
"<br />");
  builder.Append(
"imageField.Src = " + imageField.Src);
  builder.Append(
"<br />");
  builder.Append(
"imageField.VSpace = " + imageField.VSpace);
  builder.Append(
"<br />");
  builder.Append(
"imageField.Width = " + imageField.Width);      
  
return builder.ToString();
}

Result:

imageField.Alt = Alternate text
imageField.Class =
imageField.Height = 150
imageField.HSpace = 4
imageField.InternalPath = /upload/images/hist_gunung100px.jpg
imageField.IsInternal.ToString() = True
imageField.LinkType =
imageField.MediaID = {539587C7-1F36-4D94-A10D-FFFAF079B746}
imageField.MediaItem.DisplayName = hist_gunung100px jpg
imageField.Src = /upload/images/hist_gunung100px.jpg
imageField.VSpace = 4
imageField.Width = 150

 


Prev Next