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

Simple but mind blowing question it is.

Basically I am updating a specific list items through two different ways, one is using ASP.NET web forms and one is using default list forms provided by SharePoint 2007, now I don't want "Item Updated" event to run my custom code when Item is updated through ASP.NET web forms.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Setting the EventFiringEnabled property, you should get the event firing active/deactived.

share|improve this answer
    
this would work if you within the eventreciver, what if your not within the eventreciver and you dont want to call it. I presume you would need SPItemEventProperties to use that method? –  ali Sharepoint Dec 21 '12 at 14:20
add comment

You need to disable the event reciver by calling it and setting it to disabled. do your stuff and reenable the eventreciver:

someone has done most of the work for you :)

public static void RunWithEventFiringDisabled(Action action)

{

    Type typeInfo = typeof(SPEventReceiverBase);

    MethodInfo disable = typeInfo.GetMethod(“DisableEventFiring”, BindingFlags.Instance | BindingFlags.NonPublic);

    MethodInfo enable = typeInfo.GetMethod(“EnableEventFiring”, BindingFlags.Instance | BindingFlags.NonPublic);

    SPEventReceiverBase receiver = new SPEventReceiverBase();

   try
   {
        //disable it
        disable.Invoke(receiver, null);
        //do what you want to do to the list in this method 
        action();

   }
   finally
   {
        //now updating is all done you can reenable it
        enable.Invoke(receiver, null);
   }

}

code was taken from here:

www. sharepointboost .com/blog/how-to-update-an-item-or-a-folder-without-triggering-item-event-receiver/

For you or anyone you could split it into to methods where you can call the enable and disable individually

for disabling:

public static void RunWithEventFiringDisabled(Action action)
{

    Type typeInfo = typeof(SPEventReceiverBase);

     MethodInfo enable = typeInfo.GetMethod(“EnableEventFiring”, BindingFlags.Instance | BindingFlags.NonPublic);

    SPEventReceiverBase receiver = new SPEventReceiverBase();

   try
   {
        //disable it
        enable.Invoke(receiver, null);
        //do what you want to do to the list in this method 
        action();

   }
   cathc(exception a)
   {

   }
}

and for enabling:

public static void RunWithEventFiringEnabled(Action action)
{

    Type typeInfo = typeof(SPEventReceiverBase);

    MethodInfo disable = typeInfo.GetMethod(“DisableEventFiring”, BindingFlags.Instance | BindingFlags.NonPublic);

    SPEventReceiverBase receiver = new SPEventReceiverBase();

   try
   {
        //disable it
        disable.Invoke(receiver, null);
        //do what you want to do to the list in this method 
        action();

   }
   cathc(exception a)
   {

   }
}

call those two where required :)

EDIT

You could also try this as its just as good :) call this method where required instead of normal updating

public static void Update(this SPListItem item, bool doNotFireEvents)
{
    SPItemEventReceiverHandling rh = new SPItemEventReceiverHandling();
    if (doNotFireEvents)
    {
        try
        {
            rh.DisableEventFiring();
            item.Update();
        }
        finally
        {
            rh.EnableEventFiring();
        }
    }
    else
    {
        item.Update();
    }
}

http://sharepointlookup.blogspot.co.uk/2010/12/updating-splistitem-without-triggering.html#!/2010/12/updating-splistitem-without-triggering.html

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.