Deleting Event for Dynamic Module item
I need to achieve the following with my Dynamic Module:
When a Dynamic Module item is deleted, I need to delete the corresponding DocumentLibrary based on the UrlName of the Dynamic Content item.
I checked the IDynamicContentDeletedEvent interface, but it doesn't have any properties about the deleted item. Probably need an additional event here, like IDynamicContentDeletingEvent.
Is there any way I could achieve such functionality?
It is true that when Deleted event is raised the deleted item cannot be retrieved. Since we currently do not have "Deleting" event you can attach to the provider's events to track what's going on. Here is a sample how to get the UrlNames of all deleted dynamic content items in Global.asax:
Thanks for the reply and solution. This worked as expected!
Any chance a Deleting event will be part of the EventHub for Dynamic Modules?
I still have an issue regarding the code you provided.
If I open an existing Dynamic Content Item and then choose to NOT publish, but instead choose 'Back to projects list', the code determines a Deleted state. So apparently when you publish or just cancel it seems like different versions are created and older ones deleted.
Not sure how this works, but is there a way to know that the item is really deleted?
Daniel, that would be the Temp item being deleted I imagine.
Having never used Provider event hooks, I'm curious - can you successfully inspect item.Status somehwere in there and only trigger actions if it's the Master item being deleted?
Yes, Stephen, Temps also trigger the event and they are deleted when editing of an item is cancelled.
You can inspect the status of the item. On Executing all pending items are in the dirty items of the provider. The provider is the sender of the event and the dirty items are available via GetDirtyItems() method. You can inspect each item separately to see its Status as well as any other public property.
That's gold! This would have probably come in handy during a recent 6.1 experience where the IComment events were no longer being triggered... Could have simply hooked to the provider in some way.
Even without the feature it is possible to achieve the desired effect. It is true though that using the EventHub is much prettier than the Executing/Executed pattern.