Created
February 18, 2015 08:32
-
-
Save komainu85/f447007db3a2aad5c80a to your computer and use it in GitHub Desktop.
Sitecore Image Url Computed Field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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