Get Media Url From Sitecore Image Field

Xing Liu • 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;

Xing Liu

Xing has 5 years of experience with developing web solutions using ASP.NET and SQL Server. For the past 3 years, he has been actively engaged in website development projects using Sitecore CMS. He enjoys creating web solutions for clients using Sitecore CMS and, using its flexibility, provides cohesive and integrated solutions. Xing is a Sitecore Technology MVP, 2016.

Explore topics:

Other Blog Posts from Xing Liu

Subscribe for insights, trends and big ideas