Hello
My Media tree is structured as follows:
- Media (root)
- Series 1 (folder)
- Subseries 1 (folder)
- image.jpq (image)
- image2.png (image)
- …
- Subseries 2 (folder)
- anotherimage.png (image)
- …
- Subseries 1 (folder)
- Series 2 (folder)
- Subseries 1 (folder)
- Subseries 2 (folder)
- …
- …
- Series 1 (folder)
Basically the root may contain multiple levels of folders and images.
What I am trying to do is fetch all the Media content of Type “Image” (no matter where they are placed in the tree) and filter them based on a certain criteria.
How can I query the MediaAtRoot() to fetch all the “leaf” images based on a certain criteria?
This is what I tried but this returns the folder of the image, not the image itself:
var filteredImages = Umbraco.MediaAtRoot()
.Where(media => (
media.Descendants().Any(descendant => (
(descendant.ContentType.Alias == "Image") &&
(((descendant.GetProperty("projectName").GetValue()).ToString().Trim() == Model.Name().Trim())))
)
));
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/109580-querying-media