Copied to clipboard

Flag this post as spam?

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


  • Steven Wilber 103 posts 98 karma points
    Jan 27, 2010 @ 13:19
    Steven Wilber
    0

    Event Handling and Comparing to Previous Versions

    Hi,

    I don't know if anyone can help, but I'm trying to detect, by catching the event of BeforeSave for a media item, if the file (umbracoFile) has been changed.

    I'm not sure how to get to the previous version to tell. I assumed that before save then I would be able to access the existing item before the new one was saved over the top, but it seems not.

    Any help gratefully appreciated.

    Cheers

    Steve

     

  • Richard Soeteman 3614 posts 11024 karma points MVP
    Jan 28, 2010 @ 09:56
    Richard Soeteman
    0

    Hi Steve,

    No the media item object is already updated when this event gets fired. And since Media doesn't support versioning it's not possible to get the previous version also.

    Cheers,

    Richard

  • Steven Wilber 103 posts 98 karma points
    Jan 28, 2010 @ 12:54
    Steven Wilber
    0

    Fair enough.

    Thanks very much for the response Richard.

    Cheers

    Steve

  • seanrock 99 posts 173 karma points
    Aug 01, 2013 @ 13:54
    seanrock
    0

    This is a bit late but....

    Have you tried the IApplicationEvenHandler interface? Its new in (4.8+ i think). You can hook into the application start and setup a handler for the ContentType BeforeSave event. The sender is of type Content and will have the nodeId of the element that you editing.. you 'should' be able to get at it before its updated.

     

    Code Snippet
    1. public class MyApplicationEventHandler : IApplicationEventHandler
    2.     {
    3.  
    4.         public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    5.         {
    6.             
    7.         }
    8.  
    9.         public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    10.         {
    11.         }
    12.  
    13.         public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    14.         {
    15.             umbraco.cms.businesslogic.ContentType.BeforeSave += ContentType_BeforeSave;
    16.         }
    17.  
    18.         private void ContentType_BeforeSave(object sender, SaveEventArgs e)
    19.         {
    20.             Content content = sender as Content;
    21.             //
    22.             // ...
    23.             //
    24.         }
    25.     }
Please Sign in or register to post replies

Write your reply to:

Draft