views:

269

answers:

3

Hi all,

I am having trouble with temporarily disable email notification while updating items so the system will not send out any unnecessary email. What I am trying to accomplish is that disable alert, updates item, then enable alert back.

SPList tasklist = Web.Lists["Tasks"];

tasklist.EnableAssignToEmail = false; //This property makes sending mail disabled

tasklist.Update();

//Do all the update here

Item["Title"] = "New Title"; Item.update();

tasklist.EnableAssignToEmail = true; //enable email notification

tasklist.Update();

As soon as I enabled back the alert, the changes made in the middle of the code still kick off the alert and send email out.
Anyone have better idea to solve this? Thank you.

+3  A: 

Does using a SPListItem.SystemUpdate() instead still kick off the alerts?

Nat
SystemUpdate should trigger no event whatsoever so this would be my guess as well.
Colin
item.SystemUpdate() actually does trigger an alert. The reason is, alerting system does not use the event handler mechanism.
unclepaul84
Thanks.I tested it and SPListItem.SystemUpdate() did not trigger the alert.
BeerMe101
A: 

Did you try DisableEventFiring()/EnableEventFiring() pair of method calls ?

Leonidius
A: 

Thanks for the answers.

SPListItem.SystemUpdate() works great!

BeerMe101
Mark the orig answer by @Nat correct (green tick mark)
Ryan