Copied to clipboard

Flag this post as spam?

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


  • chris vdP 13 posts 35 karma points
    Feb 17, 2012 @ 18:13
    chris vdP
    0

    Getting a List of Children from a Dynamic Media Node

    Hey, I posted this over at stackoverflow, but no response there. 

    http://stackoverflow.com/questions/9318664/getting-a-list-of-children-from-a-dynamic-media-node

    So I am trying to create a photo Gallery by getting all the images in a folder from the media section. Using Umbraco 4.7.0 I used to be able to do this in Razor.

    DynamicMediaList images = new DynamicMediaList(new DynamicMedia(galleryImage).Children.Items);

    I Upgraded to 4.7.1.1 and now I get the error 'umbraco.MacroEngines.DynamicMedia' does not contain a definition for 'Children' and no extension method 'Children' accepting a first argument of type 'umbraco.MacroEngines.DynamicMedia' could be found (are you missing a using directive or an assembly reference?)

    Did some googling and found ChildrenAsList, but I can't seem to get it to cast I get the message Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.List'

    List<DynamicMedia> images = new DynamicMedia(galleryImage).ChildrenAsList;

    Any ideas on how to get this to work?

  • Douglas Ludlow 210 posts 366 karma points
    Feb 17, 2012 @ 19:52
    Douglas Ludlow
    0

    Sure, use the Library.MediaById() method. If the id of the galleryImage folder is 1234, then:

    dynamic images = Library.MediaById(1234).Children;

    ...should get you what you want.

  • Ben Norman 167 posts 276 karma points
    Feb 17, 2012 @ 20:37
    Ben Norman
    0

    Here is a link to a wiki entry which has some fun stuff on it for the media.

    http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets/simple-media-browser/media-folder-content-list

Please Sign in or register to post replies

Write your reply to:

Draft