Skip to content

Instantly share code, notes, and snippets.

@komainu85
Created February 18, 2015 08:32
Show Gist options
  • Save komainu85/f447007db3a2aad5c80a to your computer and use it in GitHub Desktop.
Save komainu85/f447007db3a2aad5c80a to your computer and use it in GitHub Desktop.
Sitecore Image Url Computed Field
public class ImageUrl : IComputedIndexField
{
public object ComputeFieldValue(Sitecore.ContentSearch.IIndexable indexable)
{
Item item = indexable as SitecoreIndexableItem;
if (item != null)
{
var fileField = ((FileField)item.Fields["Image"];
if (fileField != null && fileField.MediaItem != null)
{
var url = MediaManager.GetMediaUrl(fileField.MediaItem, new MediaUrlOptions { UseItemPath = false, AbsolutePath = false });
return url;
}
}
return null;
}
public string FieldName { get; set; }
public string ReturnType { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment