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!
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.
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):
Method 2:
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
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"
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
is working on a reply...
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.