Copied to clipboard

Flag this post as spam?

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


  • pronto 61 posts 172 karma points
    Dec 04, 2013 @ 17:17
    pronto
    0

    Issue with iterating over top level Media folder

    Hi All,

    It seems to be a common issue, but I'm trying to iterate all of the images in my media section and I'm getting some odd results. There's around 100 images in various levels of folders and I just want to target ALL of the 'Image' types but my script only ever returns the incorrect number and it doesn't make sense!

    I've tried a couple of methods, and while they seem to work for people in other threads, it doesn't work in my instance. Here's method 1 ('images' is my top media node):

    var images = Model.MediaById(1060);
    <p>@images.Descendants("Image").Count()</p>

    Method 2:

    dynamic images = new DynamicMedia(1060);
    <p>@ images.Descendants("Image").Count()</p>


    Even though there's hundreds of images, both methods returns 2; there's more than 2 immediate children as well so I'm at a loss!

    I'm using Umbraco 4.11.10!

    Cheers,
    pronto

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Dec 04, 2013 @ 22:12
    Jeavon Leopold
    0

    Hi Pronto,

    Assuming all of your media items are of media type "Image", then both of these should work, maybe you have a corrupted Examine index.

    You could try the below to check that they are of type "Image"

    var images = Library.MediaById(1060);
    <p>@images.Descendants().Count()</p>
    

    Otherwise, try stopping your application pool, then delete you Examine indexes (\App_Data\TEMP\ExamineIndexes\ Delete all sub folders and contents), restart application pool and the indexes will be recreated, see if your items turn up.

    Jeavon

Please Sign in or register to post replies

Write your reply to:

Draft