Copied to clipboard

Flag this post as spam?

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


  • Damien (Slipoch) 62 posts 346 karma points
    Aug 18, 2016 @ 03:27
    Damien (Slipoch)
    0

    I am trying to delete a media node (if found).

    I am not sure why it is not deleting this.

    //DELETE OLD FILE
                    string OldIMGId = memb.MemberProperties.Find(x => x.Alias == "profilePic").Value.ToString();
    
                    if (OldIMGId != null && OldIMGId != "")
                    {
                        IMedia temp = Umbraco.Media(OldIMGId);
                        _mediaService.Delete(temp);
                    }
    

    Does anyone know why this is not being removed?

  • Damien (Slipoch) 62 posts 346 karma points
    Aug 18, 2016 @ 23:03
    Damien (Slipoch)
    100

    Found a solution. Turns out instead of getting it via Umbraco.Media (which gets a content object) you have to use the media service and use a get call call there.

    //DELETE OLD FILE
                    string OldIMGId = memb.MemberProperties.Find(x => x.Alias == "profilePic").Value.ToString();
    
                    ///todo:Get delete media working or leave it alone? Maybe have a function that runs once every now and then and cleans up the db.
                    if (OldIMGId != null && OldIMGId != "")
                    {
                        var temp = _mediaService.GetById(int.Parse(OldIMGId));
                        if(temp!=null)
                            _mediaService.Delete(temp);
                    }
    
Please Sign in or register to post replies

Write your reply to:

Draft