Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Just use a list, and perhaps add an UIHint.
[CultureSpecific]
[Display(
Name = "Images / Attachments",
Description = "Add a media asset for the content.",
GroupName = SystemTabNames.Content,
Order = 400)]
[UIHint(UIHint.MediaFile)]
public virtual IEnumerable<ContentReference> PdfMedia { get; set; }
And, to allow PDF only, create a MediaType for PDF, and set allowed types like this
[AllowedTypes(typeof(PdfMedia))]
A ContentArea could also do the trick.
While Tomas's answer is very good (with the note to AllowedTypes which is helpful), it's worth noting that it should be IList<ContentReference> instead of IEnumerable<ContentReference>
So I have this content type I set up. Each piece of content has a description and a few text fields, but I also need to allow for an arbitrary number of assets to be added. For example, a user needs to be able to add a PDF, then have the opportunity to add a second, third, etc.
This is what I'm doing now. I have a media content type that looks like this:
using System;
using System.ComponentModel.DataAnnotations;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
using EPiServer.Framework.DataAnnotations;
namespace XXX.XXXXXX.Models.Media
{
[ContentType(DisplayName = "GenericMedia", GUID = "xxxxxxxx-bf22-4cee-93c7-xxxxxxxxx", Description = "Used for generic file types such as Word or PDF documents.")]
[MediaDescriptor(ExtensionString = "pdf,doc,docx")]
public class GenericPdfMedia : MediaData
{
[CultureSpecific]
[Editable(true)]
[Display(
Name = "Title",
Description = "Add a title of the content.",
GroupName = SystemTabNames.Content,
Order = 10)]
public virtual String Title { get; set; }
[CultureSpecific]
[Editable(true)]
[Display(
Name = "Description",
Description = "Add a description of the content.",
GroupName = SystemTabNames.Content,
Order = 20)]
public virtual String Description { get; set; }
}
}
[CultureSpecific]
[Editable(true)]
[Display(
Name = "Images / Attachments",
Description = "Add a media asset for the content.",
GroupName = SystemTabNames.Content,
Order = 400)]
public virtual ContentReference PdfMedia { get; set; }