Copied to clipboard

Flag this post as spam?

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


  • Fredrik Esseen 610 posts 906 karma points
    Feb 28, 2019 @ 13:52
    Fredrik Esseen
    0

    Cant get media items

    Hi! Im testing Umbraco 8 and got stuck on getting files the way I'm used to.

    I just made a simple loop to iterate through all folders and files in the media section but no files where found, only the folder..? I did this in a Partial view.

    var DocRootFolder = Model.Parent.Value<Folder>("docFolder");
    
    <ul class="docs">
    @foreach(var folder in DocRootFolder.Children)
    {
        <h2>@folder.Name</h2> 
    
    
        <ul>
            @foreach(var doc in folder.Children)
            {
            <li>
                <a href="@doc.Url">
                    @doc.Name
                </a>
            </li>
            }
        </ul>
    
    }
    </ul>
    

    I also tried to directly access an image just to see if I could get a hit but that gives me an error. var mediaItem = Umbraco.TypedMedia(1234);

    Are there any documentation ready for how to work with the media section?

  • Steve Morgan 1349 posts 4459 karma points c-trib
    Feb 28, 2019 @ 14:00
  • Fredrik Esseen 610 posts 906 karma points
    Feb 28, 2019 @ 14:06
    Fredrik Esseen
    0

    Yes, that is nice but now working for me in Umbraco 8.

    "'UmbracoHelper' does not contain a definition for 'TypedMediaAtRoot' and no accessible extension method 'TypedMediaAtRoot' accepting a first argument of type 'UmbracoHelper' could be found (are you missing a using directive or an assembly reference?)"

  • louisjrdev 107 posts 344 karma points c-trib
    Feb 28, 2019 @ 14:39
    louisjrdev
    0

    I believe the current equivalent would be:

    Current.UmbracoHelper.MediaAtRoot()

    there is also

    Current.UmbracoContext.MediaCache.GetAtRoot()

  • Fredrik Esseen 610 posts 906 karma points
    Mar 01, 2019 @ 11:37
    Fredrik Esseen
    0

    Just realized when testing that there were no problem with my initial code..

    I deleted the pdf-files I uploaded and added them again and then they popped up! Strange!

    So forget all I wrote :)

Please Sign in or register to post replies

Write your reply to:

Draft