Copied to clipboard

Flag this post as spam?

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


  • Dennis Spijkerboer 53 posts 95 karma points
    Dec 09, 2014 @ 15:45
    Dennis Spijkerboer
    0

    Delete media with MediaService keeps showing as IPublishedContent

    Hi,

    I run into an issue where I delete a media item by code and is still shows up if I query for IPublishedContent.

    I have the following code for deleting a media node:

    _mediaService.Delete(nodeToDelete)
    

    _mediaService is just the normal Umbraco MediaService.

    The media item is deleted in Umbraco, all seems to work fine.

    But when I query for media using the UmbracoHelper TypedMediaAtRoot my deleted media item still shows up. After I republish the entire site the cache is updated and it all works fine. I don't want te republish the site after every media item I delete. What is the best way of doing this?

    Code I use to query the media after I deleted the file (using the normal UmbracoHelper).

    _umbracoHelper.TypedMediaAtRoot()
    
  • Alan Howlett 19 posts 54 karma points
    Dec 09, 2014 @ 18:06
    Alan Howlett
    0

    What version of Umbraco are you using?

    From version 6.x, you could try using the ContentService class which has a number of methods available for managing content.

    An example usage would be:

    ApplicationContext.Current.Services.ContentService.MoveToRecycleBin(Content)

    or if you wanted to remove it and all of it's children:

    ApplicationContext.Current.Services.ContentService.Delete(Content)

    For more information on how to use this or what's available to you, download the source code for the relevant version of Umbraco you're using and look in the 'Umbraco.Core' project and you'll see a folder called 'Services'

    Hope this helps!

Please Sign in or register to post replies

Write your reply to:

Draft