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
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.
Umbraco version 8.6.4
// get image /media/myFolder/myFile.jpg
var rootFoldername = "myFolder"
var fileName = "myFile";
var imageByName = Umbraco.Web.Composing.Current.UmbracoHelper?
.FirstOrDefault(f => f.Name.Equals(rootFoldername))?
.FirstOrDefault(d => d.Name.Equals(fileName));
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted