Copied to clipboard

Flag this post as spam?

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


  • Naveed Ali 161 posts 426 karma points
    Jun 03, 2016 @ 14:01
    Naveed Ali
    0

    Media Service

    I am using media service to try and get all media items and folders, This is proving extremely difficult.

    Has anyone ever done this on umbraco v7. There seems to be countless posts on this with no replyies so is this a taboo or something??

    Thanks

    Nav

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Jun 03, 2016 @ 14:08
    Alex Skrypnyk
    0

    Hi Naveed,

    What the problem do you have?

    Cheers

  • Naveed Ali 161 posts 426 karma points
    Jun 03, 2016 @ 14:24
    Naveed Ali
    0

    Hi Alex,

    I am using media service to try and get all media items and folders.

    I want to get all items from within the folders too.

    This is what I have so far..

     var allItems = Services.MediaService.GetRootMedia();         
    
            foreach (var item in allItems)
            {
                if (allItems.)
                {
    
                }
            }
    

    I currently get all items under media and folders.

    What I am now trying to do is get into the folders and get the items within there too

    Thanks

    Nav

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Jun 03, 2016 @ 14:59
    Alex Skrypnyk
    0

    You need something like :

    var allItems = ApplicationContext.Services.MediaService.GetRootMedia();
    
    foreach (var item in allItems)
    {
        foreach (var descendant in item.Descendants())
        {
    
        }
    }
    
  • Naveed Ali 161 posts 426 karma points
    Jun 03, 2016 @ 15:11
    Naveed Ali
    0

    Hi Alex,

    I have tried that but get an error that Umbraco.Core.Models.Imedia does not contain definition for Descendants :-(

    Nav

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Jun 03, 2016 @ 15:56
    Alex Skrypnyk
    0
        var allItems = ApplicationContext.Services.MediaService.GetRootMedia();
    
        foreach (var item in allItems)
        {
            foreach (var descendant in item.Descendants())
            {
                <text>@descendant.Name</text>
            }
        }
    

    Worked for me, what version of Umbraco are you using?

    Cheers, Alex

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies