Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm trying to to prevent the deletion of media items by some CMS users. I want to do that by canceling the MediaService_Trashing event and show a warning message to the user.
Is this the way to go and are there any examples on how to do this?
Any help is appreciated :-)
I'm guessing it would be something like this:
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
MediaService.Trashing += MediaService_Trashing;
private void MediaService_Trashing(IMediaService sender, MoveEventArgs<IMedia> e)
e.CancelOperation(new EventMessage("Warning!", "You are not allowed to delete this media", EventMessageType.Error));
Not tested, but that's the theory.
Thanks for your reaction. Your code looks exactly like the thing I tried. :-) But it just doesn't seems to work. The delete gets canceled, but I don't see the message.
I think its a bug. :-(
Yep, I also have this bug in 7.5.4
Same problem here.
I guess this is really an umbraco related bug.
Not something i did.
Programming rule 1:
Always find someone to put the blame on!
This error is shown in the browser console:
Failed to load resource: the server responded with a status of 400 (Bad Request)
This may be relevant...
but the issues says that it is implemented in the media service.
So what am i missing?
e.Cancel = true;
e.Messages.Add(new EventMessage("Warning", "File cannot be delete! It is still in use.", EventMessageType.Warning));
I think it should read 'Currently only some Content and Media services...'. To date, I've found that messaging has only been enabled for some events. In particular, MediaService.Trashing and ContentService.UnPublishing don't generate messages. It's a real pain!!
Uhh thats annoying, but thanks anyway.
Im gonna look for a work-around and post it here.
Did you find a solution or workaround to this?
I am trying to do the same thing, I need to prevent certain media types from being deleted (which works fine) but show a message to the user to let them know that they cannot delete the item.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted