I have an event receiver written by someone else. It originally came with events for ItemCheckingIn and ItemCheckedIn, but we needed something to handle simple metadata updates, too. Since those don't necessarily require checkout/checkin in a document library, I added ItemUpdated to the code (I went to the properties of the event receiver thing in the project and selected "true" for that method, which added the empty method to my code, and xml goodies to elements.xml). I then tested this out and it did not work. That is, ItemCheckingIn and ItemCheckedIn still did their thing, but ItemUpdated did not. I then added ItemUpdating and tried that - still no luck.

Is there some step I'm missing here? People say all kinds of things about stuff being registered but seriously isn't that supposed to be handled by all the feature settings and stuff? Can you only add these things when you are first creating the eventreceiver in visual studio? It's not like there's an error or even would be an error - I copied the code from one of the original methods - the event just does not even fire.

Any clues out there?

Thanks,

Matt

UPDATE **

After the answer below I got a bug up my rear and went back to my solution in Visual Studio, looking for more clues. It turns out that the "feature" has C# code related to my event reciever (FeatureName.EventReciever.cs). In there, the particular events being handled are assigned to a configurable content type (set in web.config) VIA CODE. Is this normal? Should I RTFM at this point and figure out how this stuff is really done? I thought the Elements.xml for the EventReceiver handled this...

2 Answers
2

Event receivers are generally attached to lists by means of a list definition (which can define event receivers that are attached upon deployment) or programmatically through custom code. Depending on how you're deploying this event receiver, you might not actually be attaching the receiver to your list.

OK, so that did help. I discovered that my new event handlers are not registered. This is all handled through a WSP solution, though. So how can I make that automatic? As far as I know I did not have to do any powershell stuff to make this work the first time when I installed it with the original two event handlers, and retracting and deploying new versions of the solution has not changed anything either.
–
MattNov 1 '12 at 20:21

What does your solution contain? If it's deploying the list definition, then updating the Receivers part of the schema should work. Edit - so that's what enter does.. Otherwise, you can use a Feature Receiver to attach it automatically: bramnuyts.be/2011/04/01/…
–
Ted N.Nov 1 '12 at 20:28

see update above. Also in the powershell window I saw each event handler mentioned twice. Is that normal/expected?
–
MattNov 1 '12 at 20:33

1

Okay, so this feature is actually attaching the event receiver to the content type programmatically. That's a bit unusual, but if it's been working so far, it's not necessarily a problem. The 'right' way to do it is here: karinebosch.wordpress.com/walkthroughs/…. Does this feature also deploy the content type/lists, or is that separate? In regards to seeing them twice - not really sure. You might want to inspect the content type in powershell and look at its event receivers ($web.ContentTypes["Content Type Name"].EventReceivers) and see what's there.
–
Ted N.Nov 1 '12 at 20:41

It's only listed once for the web. The feature only deploys the event receivers and attendant code and WCF references. Thanks, I'll look at that link.
–
MattNov 1 '12 at 20:46

Your problem seems to be largely getting troubleshooted (troubleshot?) in the other answer's discussion thread, but to answer the specific question you're asking, there are several ways you can register/unregister event receivers:

How you do it largely depends on your approach to the solution. In other words, if you're developing a code-heavy solution, you'll probably want to do your event receiver registrations in code too, as it gives you the most flexibility and tools for diagnosis for problems such as what you're dealing with above. As an example of something I work with a lot:

Your problem seems to be largely getting troubleshooted (troubleshot?) in the other answer's discussion thread, but to answer the specific question you're asking, there are several ways you can register/unregister event receivers:

How you do it largely depends on your approach to the solution. In other words, if you're developing a code-heavy solution, you'll probably want to do your event receiver registrations in code too, as it gives you the most flexibility and tools for diagnosis for problems such as what you're dealing with above. As an example of something I work with a lot: