1

I have an Event Receiver that is supposed to fire when a SPListItem is added or updated in a SPList that is a SharePoint Calendar.

I'm using two methods, ItemAdded and ItemUpdating. When I add a new item to the calendar both methods fire. The methods are supposed to send a mail and when I add a new item the ItemUpdated() sends 7 mails.

How do I make so that only the ItemAdded and not ItemUpdated fire whenever I add a new item to the list?

Thanks.

1
  • I know this is lame: Why not use Alerts?
    – Stefan
    Apr 23, 2012 at 8:10

3 Answers 3

1

Maybe there are multiple events attached to the events?
That could explain why 7 mails are being sent..
You can see which event handlers have been registered with the sharepoint-eventhandlers-manager or SharePoint Event Receiver Manager (2007 & 2010).
Also you may want to check the documentation of the Table of SharePoint Events, Event Receivers, and Event Hosts.

3

The ItemAdded is called just once on you event receiver; an item can be added just once. The ItemUpdating and/or ItemUpdated may be called multiple times. It will depend on what receivers or what workflows are active in the list and what method they use do to update the list item. Calling SPListItem.Update() triggers the events while calling the SPListItem.SystemUpdate() does not, which makes the latter suitable for internal updates that should not be reported.

If you cannot "persuade" components that you installed to use SystemUpdate() for intermediate and other system changes ;-) you would have to think up some strategy how to avoid the "flocks of e-mails". For example, you could avoid an e-mail if it comes in less than a minute after the previous one.

I'd support Stefan's suggestion about Alerts. If you can make use of them you'd save time. I didn't notice an excessive amount of e-mails when using that. Either I was lucky having used only "well-behaving" event-receivers or Microsoft has some strategy to send e-mails when it makes sense.

--- Ferda

0

If Ferda approach does not work for you there is a way to disable events when updating a value inside of an event receiver.

Lots of examples on the web, here are two: http://www.mattjimison.com/blog/2011/05/11/disable-event-receivers-during-an-update/

https://stackoverflow.com/questions/2466533/sharepoint-workflow-how-to-update-the-item-without-triggering-the-workflow-agai

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.