1

I have uploaded all PDF files under media library. In one of my template, I added multilist with datasource to the pdf files which are created under media Library. Now in my code,I have to read the PDF files selected in the multilist from Sitecore.

I have added like below for the field in my Model.

public virtual IEnumerable<File> Documents { get; set; }

While reading the data from the GlassMapper it is throwing an exception as below.

Message = "Failed to map properties on to the Item"

Please suggest a way to read the PDF files from Sitecore using GlassMapper

4

You need to create a model first for your media items, e.g.:

[SitecoreClass]
public class MediaFile
{
    [SitecoreField("Attachment")]
    public virtual Stream File {get; set; }

    [SitecoreField("MimeType")]
    public virtual string MimeType { get; set; }

    [SitecoreField("Title")]
    public virtual string Title { get; set; }

    [SitecoreField("Size")]
    public virtual string Size { get; set; }

    [SitecoreField("Extension")]
    public virtual string Extension { get; set; }  
}

and then use it in your model:

[SitecoreField]
public virtual IEnumerable<MediaFile> Documents {get;set;}
  • What using statement is needed here for SitecoreClass? – Paul Sep 18 '18 at 7:26
  • 1
    using Glass.Sitecore.Mapper.Configuration.Attributes; – Marek Musielak Sep 18 '18 at 8:01
0

Depends what you need to do with those pdfs I would keep it as Item and used MediaManager to work with it

public virtual IEnumerable<Item> Documents { get; set; }

You can then use it like

foreach(var document in Model.Documents){
    MediaManager.GetMediaUrl(document);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.