Copied to clipboard

Flag this post as spam?

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


  • Dan Diplo 1505 posts 5911 karma points MVP 4x c-trib
    Feb 10, 2009 @ 12:56
    Dan Diplo
    0

    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.

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Feb 10, 2009 @ 13:16
    Dirk De Grave
    0

    Hi Diplo,

    Action handlers do not work on media items (v3). Event handlers are supported on media items as from v4.

    Regards,
    /Dirk

  • Dan Diplo 1505 posts 5911 karma points MVP 4x c-trib
    Feb 10, 2009 @ 13:32
    Dan Diplo
    0

    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!

  • Tim Geyssens 1060 posts 27 karma points
    Feb 10, 2009 @ 13:37
  • Ismail Mayat 4511 posts 10059 karma points MVP 2x admin c-trib
    Feb 10, 2009 @ 15:43
    Ismail Mayat
    0

    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(Media
    AfterDelete);
    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, "Media
    AfterSave fired added media " + sender.Id);
    save(sender);
    }

    private void save(Media sender) {
    //do some stuff

    }


    void MediaAfterDelete(Media sender, EventArgs e)
    {

    // do stuff

    }

    void Media
    AfterMove(umbraco.cms.businesslogic.CMSNode sender, umbraco.cms.businesslogic.MoveEventArgs e)
    {
    //do stuff
    }

    #endregion

    #region IApplication Members

    public string Alias
    {
    get { return ALIAS; }
    }

    public List

  • Dan Diplo 1505 posts 5911 karma points MVP 4x c-trib
    Feb 10, 2009 @ 21:03
    Dan Diplo
    0

    Thanks for all your help guys, that's just what I needed!

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Feb 10, 2009 @ 21:27
    Dirk De Grave
    0

    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

  • Richard Soeteman 3875 posts 12037 karma points MVP
    Feb 11, 2009 @ 09:03
    Richard Soeteman
    0

    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

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Feb 11, 2009 @ 09:31
    Dirk De Grave
    0

    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

  • Ismail Mayat 4511 posts 10059 karma points MVP 2x admin c-trib
    Feb 11, 2009 @ 09:52
    Ismail Mayat
    0

    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

  • Richard Soeteman 3875 posts 12037 karma points MVP
    Feb 11, 2009 @ 10:07
    Richard Soeteman
    0

    Thanks for the link, making sense now.

  • 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