Copied to clipboard

Flag this post as spam?

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

  • Peter van Geffen 24 posts 157 karma points
    Nov 07, 2019 @ 10:13
    Peter van Geffen

    Get an image (random) from a media folder


    What i wanted to achieve is to get a single image in a random order from a media folder (by id)

    This worked for in V7 (looking at previous projects), but now in V8 i'm stuck.

        var galleryAlbum = Umbraco.Media(1210);
        foreach(var image in galleryAlbum.Children.RandomOrder().Take(1)){
            <div class="parallax-window" data-parallax="scroll" data-image-src="@Url.GetCropUrl(image, "Hero")"></div>

    Could someone help me out?

  • Alex Skrypnyk 5729 posts 21680 karma points MVP 3x admin c-trib
    Nov 07, 2019 @ 13:54
    Alex Skrypnyk

    Hi Peter

    What about this approach:

    var galleryAlbum = Umbraco.Media(1210);
    var theList = galleryAlbum.Children.ToList();
    var randomImage = theList.ElementAt(new Random(DateTime.Now.Millisecond).Next(theList.Count()));
  • Peter van Geffen 24 posts 157 karma points
    Nov 08, 2019 @ 09:55
    Peter van Geffen

    Thank you very much! Exactly what i wanted .

Please Sign in or register to post replies

Write your reply to: