Is it possible to create Action Handlers that deal with files uploaded to the Media Library? Ideally I'd like to be able to create handlers that fired when files were added, deleted or moved. Is there any way of doing this, or do Action Handlers only work for documents.
Code snippet is no longer the preferred way to subscribe to events. Consider deriving from ApplicationBase instead of IApplication. And as in example, subscribe to the events in the class constructor.
IApplication was too bloated with interface functions you'd have to implement (Have a look at Ismail's code, it's using too many NotImplementedExceptions... which shows it's not used properly imho)
Also have a look at Ruben's blog who's been blogging about this change:
Cheers for that I was having another issue which I raised in codeplex see here and becuase Per was using IApplication I changed my code I still get that issue but that is another matter!
Action Handlers for Media Types
Is it possible to create Action Handlers that deal with files uploaded to the Media Library? Ideally I'd like to be able to create handlers that fired when files were added, deleted or moved. Is there any way of doing this, or do Action Handlers only work for documents.
Hi Diplo,
Action handlers do not work on media items (v3). Event handlers are supported on media items as from v4.
Regards,
/Dirk
Thanks, Dirk. Is there any documentation on how you subscribe to events on media items? I'm not clear how I would do this. Thanks!
Hi Diplo,
Check these examples out:
http://www.umbraco.org/documentation/books/api-cheatsheet/using-applicationbase-to-register-events
http://www.umbraco.org/documentation/books/api-cheatsheet/attaching-document-eventhandlers
Media is similar to documents (using umbraco.cms.businesslogic.media)
Diplo,
Some sample code for you
[code]
using umbraco.BusinessLogic;
using umbraco.interfaces;
using umbraco.cms.businesslogic.media;
public class MediaEventHandler : IApplication
{
const string ALIAS = "MediaEventHandler";
public MediaEventHandler() {
init();
}
private void init() {
Media.AfterSave += new Media.SaveEventHandler(MediaAfterSave);
Log.Add(LogTypes.Debug, 0, "Media event handlers Media.AfterSave registered");
Media.AfterDelete += new Media.DeleteEventHandler(MediaAfterDelete);
Log.Add(LogTypes.Debug, 0, "Media event handlers Media.AfterDelete registered");
}
#region media events
void MediaAfterSave(Media sender, EventArgs e)
{
Log.Add(LogTypes.Debug, 0, "MediaAfterSave fired added media " + sender.Id);
save(sender);
}
private void save(Media sender) {
//do some stuff
}
void MediaAfterDelete(Media sender, EventArgs e)
{
// do stuff
}
void MediaAfterMove(umbraco.cms.businesslogic.CMSNode sender, umbraco.cms.businesslogic.MoveEventArgs e)
{
//do stuff
}
#endregion
#region IApplication Members
public string Alias
{
get { return ALIAS; }
}
public List
Thanks for all your help guys, that's just what I needed!
Hi Diplo (And Ismail),
Code snippet is no longer the preferred way to subscribe to events. Consider deriving from ApplicationBase instead of IApplication. And as in example, subscribe to the events in the class constructor.
Regards,
/Dirk
Hi Dirk,
This is the second time this week that I hear a change in the preferred way. Last time was to use Basetree over Itree interface. Any more changes?
Cheers,
Richard
Hi Richard,
IApplication was too bloated with interface functions you'd have to implement (Have a look at Ismail's code, it's using too many NotImplementedExceptions... which shows it's not used properly imho)
Also have a look at Ruben's blog who's been blogging about this change:
http://ruben.3click.be/blog/changes-to-the-umbraco-event-model
Regards,
/Dirk
Dirk,
Cheers for that I was having another issue which I raised in codeplex see here and becuase Per was using IApplication I changed my code I still get that issue but that is another matter!
Regards
Ismail
Thanks for the link, making sense now.
is working on a reply...
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.