Copied to clipboard

Flag this post as spam?

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


  • Shaun 248 posts 475 karma points
    Apr 08, 2010 @ 15:48
    Shaun
    0

    Deleting media items and nodes programatically

    Hi all

    I have a .ascx control in C# that should delete selected media items and a node by their id's.

    I can't seem to find either Document.Delete or Node.Delete anywhere in intellisense.

    Can anyone point me in the right direction for this?

    Many thanks

     

    Shaun

  • Shaun 248 posts 475 karma points
    Apr 08, 2010 @ 16:05
    Shaun
    0

    I think i've worked it out.

    Document thisDoc = new Document(intID);
    thisDoc.delete();

  • Shaun 248 posts 475 karma points
    Apr 08, 2010 @ 16:25
    Shaun
    0

    Ahh. Unfortunately that didn't delete anything. 

    Also, when I try to go into admin and right-click delete the media items I'm told

    Delete failed with the following error The process cannot access the file because it is being used by another process.

    Any ideas?

     

  • Kevin Farrow 46 posts 67 karma points
    Apr 08, 2010 @ 17:32
    Kevin Farrow
    0

    Have you tried

     

     

    using umbraco.cms.businesslogic.media;

    ...

    Document
    thisMedia = new Media(intID);
    thisMedia
    .delete();
  • Kevin Farrow 46 posts 67 karma points
    Apr 08, 2010 @ 17:33
    Kevin Farrow
    0

    oops, should be...

    using umbraco.cms.businesslogic.media;

    ...

    Media
    thisMedia = new Media(intID);
    thisMedia
    .delete();
  • Shaun 248 posts 475 karma points
    Apr 08, 2010 @ 18:30
    Shaun
    0

    Brilliant. Thanks RDNZL

  • David Armitage 510 posts 2082 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() : "");
                }
            }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies