The notion of being able to
attach custom code to a slew of content type events is pretty thrilling. It's like a proverbial extra layer of cream cheese frosting in one's carrot cake, whereby custom behavior can be selectively appended to content types located across multiple libraries within a site collection.
Unfortunately, it appears (to me) that such event receivers are not supported by form content types, or those that are derived from them (such as InfoPath forms). To be clear, the
registration of the event receiver to the form content type is successful () as I'm able to see it within the content type's
SPEventReceiverDefinitionCollection. However, the overridden methods themselves (I tried the 6 basic ones ItemAdding, ItemAdded, ItemUpdated, ItemUpdating, ItemDeleted, and ItemDeleting) are never actually executed. Registering the same exact event receiver(s) to the form library itself (whose default content type is the aforementioned InfoPath form) will successfully execute the methods.
An inability to register event receivers to the content type of an InfoPath form will severely limit the scalable application potential of such custom functionality. The
SDK makes no mention of this exception; neither does the
'Event Troubleshooting' article pertaining to SharePoint event handlers.
In addition, fields promoted to library column values from InfoPath forms (and consequently mapped to their corresponding XML file content) are ReadOnly within event receivers. Unfortunately there is no error attributed to this behavior, the field updates just 'silently fail' - a discovery I made after struggling with updating the values for many hours (and finally confirming the behavior
here.
I've posted these issues to both the standard MSDN SharePoint dev forum as well as the MSDN Partner Break/Fix forum, and I'll update this posting with an information I obtain.
A couple of tools and tips that come in handy for working with SharePoint event receivers:
-
http://spm.codeplex.com/releases/view/22762 - This one for viewing the SPEventReceiverDefinitionCollection's of various objects to confirm successful registration.
-
http://www.u2u.info/Blogs/Patrick/Lists/Posts/Post.aspx?ID=1547 - This one for both viewing existing registered event receivers, as well as performing the registration itself. (Note: The tool does not possess a 'Refresh' functionality so be sure to exit and application and re-start it when you've made changes to a receiver and you need to register the new version.)
-
I was never able to update event receiver functionality when using the stsadm 'UpgradeSolution' function, in spite of the fact that I could see the updated .dll within the GAC and I always deleted/re-registered the event receiver. Instead, I had to retract/delete the solution, re-add, re-deploy it, un-register the event receiver, and re-register it.
Ah - SharePoint...never a dull moment.