How to retrieve Sitecore media item from the URL we have?
The URL is dynamic URL e.g. /~/media/14BDED00E4D64DFD8F74019AED4D74EB.ashx
.
This is generated when you add item in rich text field.
You can use the code below:
DynamicLink dynamicLink;
if (!DynamicLink.TryParse("/~/media/14BDED00E4D64DFD8F74019AED4D74EB.ashx", out dynamicLink))
return;
MediaItem mediaItem = Sitecore.Context.Database.GetItem(dynamicLink.ItemId, dynamicLink.Language ?? Sitecore.Context.Language);
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