BeerMe101
BeerMe101

Reputation: 41

how to temporarily disable email notification while updating items in code?

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.

Upvotes: 4

Views: 3483

Answers (2)

Nat
Nat

Reputation: 14305

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

Upvotes: 5

Leonidius
Leonidius

Reputation: 646

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

Upvotes: 0

Related Questions