Link to Sitecore Media Item

前端 未结 1 1046
情书的邮戳
情书的邮戳 2021-01-13 22:19

In one of my templates, I created a field named UploadedSitecoreFile and set the type to File. I did this so that when a user creates a new item, they can browse the Media L

相关标签:
1条回答
  • 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.

    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);
    
    0 讨论(0)
提交回复
热议问题