var item = Sitecore.Context.Database.GetItem(mediaItemID); if (item.Paths.IsMediaItem) { var mediaItem = new MediaItem(item); }To get the MediaItem, simply get it as a normal item (to ensure it exists and is actually a media item) and then parse it as media item.
Software development blog focusing on the Sitecore Experience Platform and Sitecore Experience Commerce.
Wednesday, September 23, 2015
Sitecore get media item from ID
When dealing with fields which are of the ImageField type is is trivial to get the media item (image) that is referenced in that field. However when using a Treelist field, which allows users to select images, you are given a delimited string of item IDs of the selected image(s).
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment