Copied to clipboard

Flag this post as spam?

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


  • Pete 213 posts 285 karma points
    Oct 12, 2012 @ 17:46
    Pete
    0

    Search mediafolders for a property?

    I want to go through each media folder and look for the value of a custom property i've made, "mycustomproperty". How can I do this in the codebehind/api?

    I tried

    var foundNodes = root.GetDescendantNodes().Where(x => x.GetPropertyAsString("mycustomproperty").Contains(searchString));

    But it returns null.

    Thanks
    Pete      

  • Tom Fulton 2030 posts 4996 karma points c-trib
    Oct 12, 2012 @ 18:09
    Tom Fulton
    0

    Hi,

    What version of Umbraco are you using?

    And what type of variable is 'root'?  I think GetDescendantNodes might only work for Content nodes.  Something like this should work for Media (in 4.9.0 with uQuery built in)

    var root = new Media(xxxx);
    var foundNodes = root.GetDescendantMedia().Where(x => x.GetProperty<string>("myValue").Contains(searchString));

    Hope this helps,
    Tom 

  • Pete 213 posts 285 karma points
    Oct 12, 2012 @ 18:56
    Pete
    0

    Hi Tom

    Thanks for the reply. I'm on 4.7.2. I've got uComponents/uQuery installed.

    For root I was using:

    umbraco.NodeFactory.Node root = umbraco.NodeFactory.Node.GetCurrent();

    What do you set for the root? -1? will that make it go through all the media nodes?

    Thanks


  • Tom Fulton 2030 posts 4996 karma points c-trib
    Oct 12, 2012 @ 19:20
    Tom Fulton
    1

    Not sure how you can start at the media root, but you could try this instead:

    var medias = uQuery.GetMediaByType("Image").Where(x => x.GetProperty<string>("myValue").Contains(searchString));

    -Tom

  • Pete 213 posts 285 karma points
    Oct 12, 2012 @ 19:54
    Pete
    0

    That did it, many thanks tom.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies