Sunday 9 August 2009

Event receiver doesn’t fire

It’s been a long, busy weekend and the brain’s gone to mush—so I’m making silly mistakes.

Starting with an existing, functional SPItemEventReceiver attached to a content type, I needed to add an extra event handler. I had ItemAdding and ItemUpdating wired up and debuggable but wanted to add a new ItemAdded handler.

On my first attempt, I simply added the extra handler method to my existing class derived from SPItemEventReceiver. When that didn’t work, I recalled originally wiring the individual handler methods within the content type definition so I added an extra Receiver element.

I realised my mistake when it dawned on me I was testing my changes against an existing list instance: having been provisioned using the original content type definition with only the ItemAdding and ItemUpdating event handlers, SharePoint will never update that instance retroactively without some custom code.

After creating a new list from the modified template, all three event handlers fire correctly.

No comments:

Post a Comment

Spam comments will be deleted

Note: only a member of this blog may post a comment.