Get Media Url From Sitecore Image Field
Posted by Xing Liu on 10/17/2014
If you have a sublayout that needs to get the URL of a media item, such as an image (item[“Image”]), here is a quick tip on how you can get that media URL.
Item item = Sitecore.Context.Item;
Sitecore.Data.Fields.ImageField imgField = ((Sitecore.Data.Fields.ImageField)item.Fields["Image"]);
string url = Sitecore.Resources.Media.MediaManager.GetMediaUrl(imgField.MediaItem);
string altText = imgField.Alt;