Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Jul 26 '12 at 13:00

This question came from our site for professional and enthusiast programmers.

    
I know this is lame: Why not use Alerts? –  Stefan Apr 23 '12 at 8:10
add comment

3 Answers 3

up vote 1 down vote accepted

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

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/

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.