Can't work out how to display an image I have in a Media subfolder in razor. It's not attached to a page at all and I want to be able to call it by it's name parameter.
The image is in the Media section in a directory called "backgrounds", it can be any file name but the "Name" parameter must be "Biography Page". I'm probably going at it from the wrong angle but can't find out enough about the Umbraco razor object model to navigate it myself.
Get Image by Name
Hi,
Can't work out how to display an image I have in a Media subfolder in razor. It's not attached to a page at all and I want to be able to call it by it's name parameter.
dynamic mediaItem = @Model.Media.backgrounds.Image.Name("Biography Page").umbracoFile;
Doesn't work of course.
The image is in the Media section in a directory called "backgrounds", it can be any file name but the "Name" parameter must be "Biography Page". I'm probably going at it from the wrong angle but can't find out enough about the Umbraco razor object model to navigate it myself.
Any help would be appreciated.
Craig
Umbraco version 8.6.4
// get image /media/myFolder/myFile.jpg
var rootFoldername = "myFolder" var fileName = "myFile";
var imageByName = Umbraco.Web.Composing.Current.UmbracoHelper? .MediaAtRoot()? .FirstOrDefault(f => f.Name.Equals(rootFoldername))? .Children()? .FirstOrDefault(d => d.Name.Equals(fileName));
is working on a reply...