Copied to clipboard

Flag this post as spam?

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


  • Anamarija Horvat 25 posts 140 karma points
    Feb 17, 2017 @ 18:09
    Anamarija Horvat
    0

    Deleted Media still showing

    I am looping through media folder with certain Id to display images. I deleted some of images from there and I don't see them in back office, but I still get them while looping, it acts like they are still there. Here is the code:

    var media = Umbraco.Media(1472);
    @foreach (var file in media.Children)
    {
          var ImageId = Umbraco.Media(file.Id);
          var Image = ImageId.UmbracoFile;
          <img src="@Image" class="lightbox-image "/>
    }
    

    In variable "Image" there are still deleted files Url's. Since they're deleted It renders on my page as "Url not found". Why is it doing it? How can I really delete something from folder, or how to display only items that aren't deleted.

  • Stefano 61 posts 312 karma points c-trib
    Feb 17, 2017 @ 18:50
    Stefano
    0

    Is it that they are in the bin, so unpublished and not in the main media folder?

  • Anamarija Horvat 25 posts 140 karma points
    Feb 17, 2017 @ 19:00
    Anamarija Horvat
    0

    This shouldnt have any relation to this. You can add file and delete them in Umbraco media section. Adding works fine, but deleting doesnt. File is deleted and not there but looping still returns url for example /media/1024/image5.jpg even tough theres nothing there

  • Paul Wright (suedeapple) 264 posts 666 karma points
    Feb 18, 2017 @ 10:35
    Paul Wright (suedeapple)
    2

    Try something like this

     var media = Umbraco.TypedMedia(1472).Children.Where(x => x.IsVisible());
    
    @foreach (var img in media)
    {
        <img src="@img.Url" class="lightbox-image" />
    }
    
  • Anamarija Horvat 25 posts 140 karma points
    Feb 20, 2017 @ 08:17
    Anamarija Horvat
    0

    This returns the error: cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

    I tried this:

    @foreach (var file in media.Children.Where("Visible"))

    But didn't solve my issue

  • Anamarija Horvat 25 posts 140 karma points
    Feb 20, 2017 @ 08:29
    Anamarija Horvat
    0

    But this:

    @foreach (var file in media.Children.Where("Visible"))
        {
            if(file.IsVisible)
    

    Returns false for all files. Nothing is published, because it's in media section and there's not publish button there

  • Paul Wright (suedeapple) 264 posts 666 karma points
    Feb 20, 2017 @ 11:35
    Paul Wright (suedeapple)
    0

    Something like this should do it

        var media = Umbraco.TypedMedia(1089).Children.OfTypes("Image").Where(x => x != null);
    
    
    @foreach (var img in media)
    {
    
        <img src="@img.Url" class="lightbox-image" />
    }
    

    Also in your Developer Section, check the XML Cache integrity for the Media Items.

  • Anamarija Horvat 25 posts 140 karma points
    Feb 20, 2017 @ 14:37
    Anamarija Horvat
    0

    It does not. It's not null, Umbraco doesn't delete meta data. So I can even get height, type, all the information about deleted file. Bascially everything is kept except file itself.

  • Stefano 61 posts 312 karma points c-trib
    Feb 20, 2017 @ 15:00
    Stefano
    0

    Not too sure but I reckon you can check if the file inside the media element is != null (I think is called umbracoFile) or the url is null

  • Anamarija Horvat 25 posts 140 karma points
    Feb 20, 2017 @ 15:13
    Anamarija Horvat
    0

    That's my question actually, I dunno how to check is it null, because url itself isn't. I get /media/1024/image5.jpg for example.

  • Stefano 61 posts 312 karma points c-trib
    Feb 20, 2017 @ 15:17
    Stefano
    0

    is .GetPropertyValue("umbracoFile") == null?

  • Anamarija Horvat 25 posts 140 karma points
    Feb 20, 2017 @ 15:47
    Anamarija Horvat
    0

    That's not null, that returns that url. I switched to another approach that I don't like very much, but it works. Instead of looping through folder, I made API where user needs to select all images himself through Multi Media Picker. That works but it's not what I wanted. I dunno why Umbraco acts the way he does and keeps all meta data.

  • Paul Wright (suedeapple) 264 posts 666 karma points
    Feb 20, 2017 @ 15:51
    Paul Wright (suedeapple)
    0

    What version of umbraco are you running?

  • Anamarija Horvat 25 posts 140 karma points
    Feb 22, 2017 @ 15:39
    Anamarija Horvat
    0

    7.4.3

  • Lee Kelleher 3938 posts 15122 karma points MVP 10x admin c-trib
    Feb 22, 2017 @ 15:47
    Lee Kelleher
    0

    Hi Anamarija,

    I got hit by this too... it's a bug, fixed in Umbraco v7.5.5

    http://issues.umbraco.org/issue/U4-9137

    If you can't upgrade, then the best you can do is to check the media node's Path, see if it starts with "-1,-21,".

    Cheers,
    - Lee

  • Anamarija Horvat 25 posts 140 karma points
    Feb 22, 2017 @ 15:51
    Anamarija Horvat
    0

    Thank you!

  • Damiaan 438 posts 1290 karma points MVP 3x c-trib
    Feb 21, 2017 @ 10:49
    Damiaan
    0

    Sounds like your examine indexes are not up to date.

    If you search for the media items in the develop tab, can you still find this image? which you are referring? If so, rebuild the index.

  • Anamarija Horvat 25 posts 140 karma points
    Feb 22, 2017 @ 15:42
    Anamarija Horvat
    0

    I am sorry I don't understand. I don't see media in developer's tab, and unfortuanatly don't know what examine indexes are. Can you elaborate so I can rebuild them. But if you ask do I see media in Media section I don't.

  • James Strugnell 84 posts 192 karma points
    Jan 30, 2018 @ 11:19
    James Strugnell
    0

    I just had this same issue running 7.6.1. Tried everything, then found this article and an Examine re-index fixed it.

  • David Armitage 412 posts 1652 karma points
    Jun 21, 2020 @ 04:07
    David Armitage
    0

    Hi Guys

    Anyone having trouble with Umbraco 8. Here is how I do it.

    public void DeleteMedia(int mediaId)
            {
                try
                {
                    IMedia media = _mediaService.GetById(mediaId);
                    if(media != null)
                        _mediaService.Delete(media);
    
                }
                catch (Exception e)
                {
                    _logger.Error<UmbMediaService>("DeleteMedia | Exception: {0} | Message: {1}", e.InnerException != null ? e.InnerException.ToString() : "", e.Message != null ? e.Message.ToString() : "");
                }
            }
    
Please Sign in or register to post replies

Write your reply to:

Draft