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).
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.
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;
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:
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.
Cheers, Lee.
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:
HTH,
Hendy
Btw, why not just use the Meda object from the 2nd line, so:
HTH,
Hendy
Thanks Hendy - it's easy / obvious when you know how ;-)
is working on a reply...