Hi, I was wondering if anyone could help me with this:
How can I loop through all children in the root media folder? Trying to do this with Razor in Umbraco 7.1.4
My problem is I need some way to find media files without using their IDs. As far as I can tell you can't get nodes directly by name, so the best solution I can think of is to traverse down through the media folder tree and find the files that way.
Now I just need to figure out how to access the root folder.
UmbracoHelper has method TypedMediaAtRoot() returning IEnumerable of IPublishedContent - this will be the list of medias under the media root. Then you are able either to traverse media hierarchy or to call extension method FlattenList(media => media.Children) on IEnumerable
Referencing the root media folder
Hi, I was wondering if anyone could help me with this:
How can I loop through all children in the root media folder? Trying to do this with Razor in Umbraco 7.1.4
My problem is I need some way to find media files without using their IDs. As far as I can tell you can't get nodes directly by name, so the best solution I can think of is to traverse down through the media folder tree and find the files that way.
Now I just need to figure out how to access the root folder.
Hi Gitte,
Do you have some progress with your issue? Why do you need to get media by name?
Hi Gittie
UmbracoHelper has method TypedMediaAtRoot() returning IEnumerable of IPublishedContent - this will be the list of medias under the media root. Then you are able either to traverse media hierarchy or to call extension method FlattenList(media => media.Children) on IEnumerable
Just for ref - here is an extension method I implemented to get a media URL by media 'path'. You can adapt it for your needs.
For example, calling this method with argument 'Main Site Images/Locations/Brazil/Brazil_1.jpg' will return URL of the image you see on the screenshot
is working on a reply...