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 a situation where I don't want to trigger the ItemAdded event if an item is added to a list via a workflow. Is it possible not to trigger this event?

share|improve this question
    
why dont leave it empty, if you dont want it to do anything ? –  Muhammad Raja Jul 18 '12 at 14:53
    
When items are not added by my workflow I want to do some checks on the item. –  John Jul 18 '12 at 14:56
add comment

3 Answers 3

Might want to take a look at this article http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.speventreceiverbase.disableeventfiring(v=office.12).aspx

Basically, what your looking for is something like this

base.DisableEventFiring();
item.update();
base.EnableEventFiring();
share|improve this answer
add comment

Following Caesar answer I knew what to google for.

The nicest thing I have seen is from Adrian Henke's blog

/// <summary>
/// Disabled item events scope
/// </summary>
/// <see cref="http://adrianhenke.wordpress.com/2010/01/29/disable-item-events-firing-during-item-update/"/>
class DisabledItemEventsScope : SPItemEventReceiver, IDisposable
{
    bool oldValue;

    public DisabledItemEventsScope()
    {
        this.oldValue = base.EventFiringEnabled;
        base.EventFiringEnabled = false;
    }


    public void Dispose()
    {
        base.EventFiringEnabled = oldValue;
    }    

}

You can then call your code in:

using (DisabledItemEventsScope scope = new DisabledItemEventsScope())
{
    item.SystemUpdate(); // will NOT fire events
}
item.SystemUpdate(); // will fire events again

The nice thing is that if anything goes wrong events will be turned back on automatically.

share|improve this answer
add comment

Could always have the workflow update a hidden column and the event receiver looks to see if there is any data in that column. If yes, do nothing, if no, process.

share|improve this answer
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.