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.
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.
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
public class MyApplicationEventHandler : IApplicationEventHandler
{
public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
}
public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
}
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
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
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
Fair enough.
Thanks very much for the response Richard.
Cheers
Steve
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.
is working on a reply...