Access file drop area fields
Version: 10.4
You can use the Sitecore.Data.Fields.FileDropAreaField class to access the value in a field of type File Drop Area (FDA). The Sitecore.Data.Fields.FileDropAreaField.GetMediaItems method returns the media items associated with the FDA field.
You can implement a Web control based on the following example that generates an unordered list of links to the media items associated with an FDA field.
RequestResponse
namespace Sitecore.Sharedsource.Web.UI.WebControls
{
using System;
public class FDALinks : Sitecore.Web.UI.WebControl
{
public string FieldName
{
get; set;
}
protected override void DoRender(System.Web.UI.HtmlTextWriter output)
{
if (this.FieldName == null || Sitecore.Context.Item == null || output == null)
{
return;
}
Sitecore.Data.Fields.FileDropAreaField fdaField = Sitecore.Context.Item.Field[this.FieldName];
if (fdaField == null) {
return;
}
Sitecore.Collections.ItemList mediaItems = fdaField.GetMediaItems();
if (mediaItems.Count < 1) {
return;
}
output.Write("<ul>");
foreach (Sitecore.Data.Items.Item mediaItem in mediaItems)
{
string mediaUrl = Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem));
string markup = String.Format(@"<li><a href=""{0}"">{1}</a>", mediaUrl,mediaItem.Name);
output.Write(markup);
}
output.Write("</ul>");
}
}
}