Link to Sitecore Media Item

In one of my templates, I created a field called UploadedSitecoreFile and set the type to File. I made it so that when the user creates a new item, he can browse the media library and select the PDF file to which they want to bind.

In my code, I have the following:

Dim subItem = TryCast(e.Item.DataItem, Item) ltResourceInfoTag.Text = ltResourceInfoTag.Text & "<a href='" & subItem("UploadedSitecoreFile").ToString & "'>" & subItem("Name").ToString & "</a>" 

Can someone tell me the correct way to link to a multimedia element?

Thanks CR Junk

+4
source share
1 answer

You need to take a look at using Sitecore.Resources.Media.MediaManager to get the URL of the media library item.

Before you get there, open the field and put it in a FileField . When you have FileField , you can access MediaItem .

Example ( C# not VB sorry):

 Item subItem = Sitecore.Context.Item; Sitecore.Data.Fields.FileField fileField = ((Sitecore.Data.Fields.FileField)subItem.Fields["UploadedSitecoreFile"]); string url = Sitecore.Resources.Media.MediaManager.GetMediaUrl(fileField.MediaItem); 
+21
source

Source: https://habr.com/ru/post/919066/


All Articles