Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • wilmar 19 posts 129 karma points
    Feb 10, 2021 @ 08:28
    wilmar
    0

    How can i find out which folder belongs to an image im umbraco 8

    Hi i have i folder in media called my private photos for example im using media service to get the image as IMedia

    _mediaService.GetMediaByPath("/media/adgasgd/someimage.jpg")
    

    how can i find out witch folder this image belongs to ? I need to read custom properties from this folder

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Feb 14, 2021 @ 14:18
    Huw Reddick
    0
    var myImage = _mediaService.GetMediaByPath("/media/adgasgd/someimage.jpg")
    var folder = _mediaService.GetById(myImage.ParentId);
    
  • Thomas Kassos 54 posts 265 karma points
    Feb 14, 2021 @ 23:20
    Thomas Kassos
    0

    Hi wilmar,

    I have found easier to use the umbraco helper and work with IPublished content.

    so if you are getting the image from the path then you can do that

    var myImage = _mediaService.GetMediaByPath("/media/adgasgd/someimage.jpg");
    
    var uHelper = Umbraco.Web.Composing.Current.UmbracoHelper;
    
    var iPublishedContentMyImage= uHelper.Media(myImage.Id);
    
    var privatePhotosFolder= iPublishedContentMyImage?.AncestorsOrSelf()?.Where(x => x.Name == "private photos")?.FirstOrDefault();
    
    if(privatePhotosFolder != null){
    ...
    }
    

    With this one you can have multiple folders under your "Private Photos" folder

    (btw its not tested)

    Hope that helps

Please Sign in or register to post replies

Write your reply to:

Draft