Copied to clipboard

Flag this post as spam?

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


  • Gordon Saxby 1461 posts 1883 karma points
    Mar 01, 2012 @ 15:20
    Gordon Saxby
    0

    How to read Multi-Node Tree Picker

    I am using the tree picker on a DocType and need to get the selected image (there is only one allowed) within a UserControl. I have this at the moment but it doesn't work:

                var xml = uQuery.GetCurrentNode().GetProperty("productImage");
                var selectedNodes = uQuery.GetMediaByXml(xml.ToString());
                var imgId = Convert.ToInt32(selectedNodes.First().getProperty("nodeId").Value);
    Getting the property works (first line) and I can see the XML while debugging, but the next line returns nothing.
    I want to end up with node ID which I can then use to create a Media node (to get various details from).

     

     

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Mar 01, 2012 @ 15:24
    Lee Kelleher
    0

    Hi Gordon,

    By calling "GetMediaByXml", you will get back a list of Media objects.  They don't have a property called "nodeId", so you can just access the object ID itself.

    var imgId = selectedNodes.First().Id;

    Cheers, Lee.

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Mar 01, 2012 @ 15:29
    Hendy Racher
    0

    Hi Gordon,

    I'm guessing that the xml value in the first line isn't an xml string, but an Umbraco Property object, if you do: GetProperty("productImage").Value this could fix it.

    (after editing this post, and the angle brackets disappearing the above might not be true.... Lee beat me to it and is correct)

    Alternatively how about:

    string xml = uQuery.GetCurrentNode().GetProperty<string>("productImage");
    List<media> selectedMedia = uQuery.GetMediaByXml(xml);
    int imageId = selectedMedia.First().Id;

    HTH,

    Hendy

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Mar 01, 2012 @ 15:36
    Hendy Racher
    0

    Btw, why not just use the Meda object from the 2nd line, so:

    Media media = uQuery.GetMediaByXml(
    uQuery.GetCurrentNode()
    .GetProperty<string>("productImage")
    ).First();

    HTH,

    Hendy

  • Gordon Saxby 1461 posts 1883 karma points
    Mar 01, 2012 @ 22:54
    Gordon Saxby
    0

    Thanks Hendy - it's easy / obvious when you know how ;-)

Please Sign in or register to post replies

Write your reply to:

Draft