Copied to clipboard

Flag this post as spam?

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


  • Trevor Loader 199 posts 256 karma points
    Mar 02, 2011 @ 08:00
    Trevor Loader
    0

    Extract media with certain property values

    I cannot figure this out.

    I have memberId as a property in the image media type.  Ideally, I want to putt out all images with a certain memberId.

    If these were documents, I could use something like this...

    var memberId = 1234;var values = new Dictionary<string, object>();values.Add("memberId", memberId) ;        var items = node.Children.Where(MemberId <= memberId", values);

    I've found documentation on DynamicMedia and MediaById - but I cannot get these working at all.

     

    Any help would be much appreciated.

    NOTE I'm using 4.7RC

  • Trevor Loader 199 posts 256 karma points
    Mar 02, 2011 @ 21:51
    Trevor Loader
    0

    OK, so I've managed to get a simple example using NodeById working...but MediaById does not.

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{ var children = @Model.NodeById(1074).DescendantsOrSelf(); }
    @foreach (var item in @children) {
        @item.Name
    }

    @{ var mediaFolder = @Model.MediaById(1198).DescendantsOrSelf(); }
    @foreach (var item in @mediaFolder) {
        @item.Name
    }

     

    The above razor script (cshtml) shows a loop through nodes which successfully outputs the name of all descendants below the hard coded node id (via NodeById)

    However the second statement (MediaById) throws an error as'umbraco.MacroEngines.DynamicMedia' does not contain a definition for 'DescendantsOrSelf'.  I've also tried 'Children' instead of DescendantsOrSelf but that throws the same error.

    Any idea of how to get Children of Media?


     

     

     

  • Gareth Evans 142 posts 334 karma points c-trib
    Mar 09, 2011 @ 08:03
    Gareth Evans
    0

    The children helper methods (Descendants, Children etc) are only implemented on DynamicNodeList/DynamicNode, not on DynamicMedia

    We intentionally didn't implement these because Media isn't cached, and as a result, you'd end up with performance problems.

    I'll think about the best way to solve this prob

  • Dominic Dore 18 posts 38 karma points
    Jun 01, 2011 @ 16:49
    Dominic Dore
    0

    I am having an issue with getting media to display using a .net user control. I have a node called currentPage (which is the current page), then I go through each child page and get all of the childrens' "properties." I use those properties to display certain content on the current page, and one of those properties that I need to display is the child page's "mediaArea" (which is the alias). mediaArea contains the image(s) that I am trying to display on the parent page, but I just don't know how to do it using .net user controls. The current code that I am trying to use to display the images looks like this: sw.WriteLine(string.Format(@"<img src=""{0}"" />", child.GetProperty("mediaArea").Value));, where sw is my StringWriter. Anyone have any suggestions?

    Thanks!

    - Dom

Please Sign in or register to post replies

Write your reply to:

Draft