Wednesday 29 May 2013

Retrieve full img url from sitecore for display on site

sitecore can be quite counter intuitive at times and this is one big example of it. 

If you want the actual img url to display on your web site using an <img src="" /> you won't find that in the metadata carried with the MediaItem object. 

Instead you have to make a separate call to sitecore like this:

Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem)

and remember you can always get a MediaItem from an ImageField if that is what you have by doing imageField.MediaItem. 

No comments:

Post a Comment