I cant find any example how to programmatically delete file (image). I think that i should use DeleteMediaFile(string filepath) but i dont know how to use it to delete for example news image.
You can use
Umbraco.Web.Composing.Current.Services.MediaService.Delete(media-item)
on a Media-item, given that you'd have the media-item.
Otherwise, to get it by ID first: MediaService.GetById(id)
How to programmatically delete file?
Hi all,
I cant find any example how to programmatically delete file (image). I think that i should use DeleteMediaFile(string filepath) but i dont know how to use it to delete for example news image.
Any help is apriciated.
Thanks
Josip
You can use
Umbraco.Web.Composing.Current.Services.MediaService.Delete(media-item)
on a Media-item, given that you'd have the media-item. Otherwise, to get it by ID first:MediaService.GetById(id)
Hi Guys,
For completeness here is how I do it for Umbraco 8.
is working on a reply...