Copied to clipboard

Flag this post as spam?

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


  • Bendik Engebretsen 105 posts 202 karma points
    Mar 03, 2016 @ 14:32
    Bendik Engebretsen
    0

    List all images in Media

    I'm trying to create a slide show for my site which shows all the images on the site. Can anybody help me with the razor code for getting a list of all media of type "Image"?

    My code for getting a specific image goes like this

    var image = Umbraco.TypedMedia(1080);
    string imgUrl = image.GetPropertyValue<string>("umbracoFile");
    <img src="@imgUrl" />
    
  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Mar 03, 2016 @ 14:35
    Dennis Adolfi
    1

    You could:

    var images = uQuery.GetMediaByType("Image");
    

    And then:

    @foreach (var img in images)
    {
        var image = Umbraco.TypedMedia(img.Id);
        string imgUrl = image.GetPropertyValue<string>("umbracoFile");
        <img src="@imgUrl" />
    }
    

    Hope it helps.

  • Bendik Engebretsen 105 posts 202 karma points
    Mar 04, 2016 @ 08:19
    Bendik Engebretsen
    0

    Thanks Dennis, exactly what I was looking for!

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Mar 04, 2016 @ 08:26
    Dennis Adolfi
    0

    Great to hear! Glad it helped! :)

    ´wink´ Mark as solution. :)

Please Sign in or register to post replies

Write your reply to:

Draft