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

How do I disable event firing in code that is not part of an ItemReceiver?

E.g.: I have an FeatureActivated event receiver which update a list (adds column) and updates all items to populate the new column. I want to do this without firing the 'ItemUpdated'-event for all items in the list.

share|improve this question
    
What I don't understand is : Events firing may be disabled for which SharePoint objects/area/domain/scope : web ? Farm ? list ? Item ? Where is the association made ? Many thanks –  user16325 Apr 12 '13 at 15:07
    
@user16325 See this Question: sharepoint.stackexchange.com/questions/20261/… –  Dribbel Apr 13 '13 at 15:42
add comment

1 Answer

up vote 8 down vote accepted

You can use this approach - create class:

public class DisabledItemEventsScope : SPItemEventReceiver, IDisposable
{
    private readonly bool oldValue;

    public DisabledItemEventsScope()
    {
        oldValue = EventFiringEnabled;
        EventFiringEnabled = false;
    }

    #region IDisposable Members

    public void Dispose()
    {
        EventFiringEnabled = oldValue;
    }

    #endregion
}

using:

using (var scope = new DisabledItemEventsScope())
{
   Item.Update();
}

from here

share|improve this answer
    
Nice and clean! –  Dribbel Mar 15 '12 at 15:00
    
Should this work for updating any item properties without firing an event, or just in that specific situation? –  thanby Jan 24 '13 at 14:16
    
This will work for any item update –  Kai Jan 24 '13 at 14:48
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.