I use the following to get, for instance, the header of the current page;
Header = Sitecore.Context.Item["Header"]
But how would i go about getting the src url of a image field?
PictureSrc = Sitecore.Context.Item["MyImage"]
You will want to look at leveraging the Sitecore.Resources.Media.MediaManager to get the URL to a media library item.
Before you get there, get the field from the item and cast it to a FileField. Once you have a FileField you can get access to the MediaItem.
Item item = Sitecore.Context.Item;
Sitecore.Data.Fields.ImageField imgField = ((Sitecore.Data.Fields.ImageField)item.Fields["MyImage"]);
string url = Sitecore.Resources.Media.MediaManager.GetMediaUrl(imgField.MediaItem);
string altText = imgField.Alt;
Link to Sitecore Media Item
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With