Copied to clipboard

Flag this post as spam?

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


  • Yoadd 6 posts 76 karma points
    Jul 26, 2022 @ 07:03
    Yoadd
    0

    Querying Media

    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)
        • ...
      • Series 2 (folder)
        • Subseries 1 (folder)
        • Subseries 2 (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())))
                                    )
                          ));
    
  • GregoryWilliams 9 posts 80 karma points
    Jul 28, 2022 @ 04:57
    GregoryWilliams
    0

    This is the new for me. Please someone tell me more about that.

  • Yoadd 6 posts 76 karma points
    Jul 28, 2022 @ 06:44
    Yoadd
    0

    I managed to solve this using DescendantsOrSelf

    Umbraco.MediaAtRoot()
            .DescendantsOrSelf<IPublishedContent>()
            .Where(...)
    
  • 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" button below.

    Continue discussion

Please Sign in or register to post replies