Copied to clipboard

Flag this post as spam?

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


  • Carl Sjöholm 44 posts 327 karma points
    May 13, 2020 @ 09:44
    Carl Sjöholm
    0

    Get specific propertytypes not based on alias

    Hi.

    I want to use the sitemap extension:

    https://blog.spotibo.com/sitemap-guide/#4-2-image-sitemap-extension

    Since there could be multiple pages with multiple properties that are images, how do I get all images?

    var images = child.Properties
            .Where(x => x.PropertyType.IsUserProperty &&
                        x.PropertyType.ContentType.ItemType == PublishedItemType.Media)
            .ToList();
    

    This gets all media I guess. But I only want images.

  • Carl Sjöholm 44 posts 327 karma points
    May 24, 2020 @ 09:42
    Carl Sjöholm
    0
    var images = page.Properties
        .Where(x => x.PropertyType.IsUserProperty &&
                    x.PropertyType.ContentType.ItemType == PublishedItemType.Media &&
                    x.HasValue() && x.Value() is Image)
        .Select(x => x.Value<Image>())
        .ToList();
    

    This seems ok but not optimal. Any other suggestions?

  • Nik 1617 posts 7263 karma points MVP 7x c-trib
    May 24, 2020 @ 11:48
    Nik
    100

    Hi Carl,

    It would depend on your version of Umbraco to be honest, but no that isn't going to cover all of your scenarios.

    You have to consider content such as "Grid", "Nested Content" and RTE's as well as each of these add a deeper level of complexity. Not to mention any custom data types as well.

    In some respects, your easier option might be to create your own "image index" when a page is published, so you can crawl the HTML and find them, for example.

    However, if you are running version 8.6.*+ you might have access to the media tracking data that is stored in the database. This should be able to tell you where images are used so you can retrieve it that way. (I've not tried it, so I'm only able to try and point you in the direction of options I'm afraid)

    Nik

  • Carl Sjöholm 44 posts 327 karma points
    Jun 06, 2020 @ 07:54
    Carl Sjöholm
    0

    Hi.

    Umbraco 8.6 +.

    I've tried to find how to access media tracking in code.

    But there are no example code how to search for media for a specific page.

Please Sign in or register to post replies

Write your reply to:

Draft