Copied to clipboard

Flag this post as spam?

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


  • Stephen Balmer 18 posts 38 karma points
    Aug 01, 2012 @ 17:37
    Stephen Balmer
    0

    DynamicMedia, DynamicNodeList and the .Where clause

    I'm having trouble getting the .Where clause to work with DynamicMedia.

    I want to get the descendants of a certain media folder, and then filter out all the folders.

    I can explicitly code this but i came across the .Where option and figured it would be a much more elegant way to do this.

    Unfortunately, it just isn't happening...

    var images = new DynamicMedia(rootNode).Descendants().Where("NodeTypeAlias == \"Image\"");

    Any ideas?

    Thanks in advance.
    S.

     

     

  • Douglas Ludlow 210 posts 366 karma points
    Aug 01, 2012 @ 19:16
    Douglas Ludlow
    0

    You're close, but you aren't using DynamicMedia dynamically. Use Library.MediaById() which returns the dynamic version of the DynamicMedia object.

    var images = Library.MediaById(-1).Descendants().Where("NodeTypeAlias == @0", "Image");

    Also, the Descendants() method takes a the NodeTypeAlias as a parameter, so the above snippet can be shortened to:

    var images = Library.MediaById(-1).Descendants("Image");

    Check out the Razor DynamicNode Cheatsheet for a list of all the available properties and methods. It may also be helpful to run through the Umbraco 4.7 Razor Feature Walkthrough.

  • Stephen Balmer 18 posts 38 karma points
    Aug 02, 2012 @ 10:32
    Stephen Balmer
    0

    Ok, that's still not working.

    Firstly, I am using this in a .ashx file so I haven't been able to find which using statement is needed to access Library.

    Looking on the web I read to substitue RazorLibraryCore(null).MediaById for Library.MediaById.

    That seemed to compile ok but then I get an error of "Can only unbox from an object or interface type to a value type".

     

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft