Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Matthew Watts 5 posts 76 karma points
    Feb 21, 2019 @ 20:24
    Matthew Watts
    0

    Content Page to show uploaded files

    Hi, I need some help. I want a content page where a content editor can upload files(pdf's, Word docs etc) and then viewed on the website. I have the following structure to achieve this. Any idea how i can fix this or use a better way of displaying uploaded files to a page?

    I have a content page called Team Documents where you can upload the files using a document type which has a TreePicker.

    I then have the code below , in the Template, which i want to loop through the page and display the url for each document.

    @{ Layout = "Master.cshtml"; }

    @{ var umbracoHelper = new UmbracoHelper(UmbracoContext.Current); var teamDocuments = Model.Content.GetPropertyValue<>

    foreach (var item in teamDocuments)
    {
        <img src="item.Url" style="width:200px" />
    }
    

    }

    When i run this code i get the error below:

    Microsoft.CSharp.RuntimeBinder.RuntimeBinderException HResult=0x80131500 Message='Umbraco.Web.PublishedContentModels.TeamDocuments' does not contain a definition for 'GetPropertyValue' Source=

    Thanks

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Feb 21, 2019 @ 22:53
    Alex Skrypnyk
    0

    Hi Matthew

    First of all remove this line:

    var umbracoHelper = new UmbracoHelper(UmbracoContext.Current); 
    

    You always have Umbraco helper in views, just use "Umbraco" magic word.

    The second block should be like that:

    var teamDocuments = Umbraco.AssignedContentItem.GetPropertyValue<IEnumerable<IPublishedContent>>("teamDocuments ");
    
    foreach (var item in teamDocuments)
    {
        <img src="@item.Url" style="width:200px" />
    }
    

    Thanks,

    Alex

  • Matthew Watts 5 posts 76 karma points
    Feb 22, 2019 @ 20:22
    Matthew Watts
    0

    Hi Alex,

    When i remove the first line from the view i get "an object reference is required.....".

    If i leave it in and use your code to get the items i get a null reference message.

    Thanks,

    Matthew

Please Sign in or register to post replies

Write your reply to:

Draft