Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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.
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.
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".
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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.
You're close, but you aren't using DynamicMedia dynamically. Use Library.MediaById() which returns the dynamic version of the DynamicMedia object.
Also, the Descendants() method takes a the NodeTypeAlias as a parameter, so the above snippet can be shortened to:
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.
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".
is working on a reply...