2

I am using some of these such as ItemAdded and ItemUpdated and I had altered the elements file to make this synchronous.

I'm just curious as to what the order of execution is for all these handlers.

What I noticed with my set up is that, ItemUpdated fires right after ItemAdded but before the properties dialog appears. And then it fires after the properties dialog is submitted.

I want to move the file after it has been added and properties updated - is there any way to determine this??

thanks,

KS

3 Answers 3

4

The order of the events if pretty clear (ItemAdding – ItemAdded – ItemUpdating – ItemUpdated, and others e.g. when you delete, emailReceived, WorkflowStarted, etc.), but how many there are triggered could differ depending on the application (e.g. WebUI, Word document Save as, and more important - custom implementations!).

E.g. while working on properties screen (after Upload) - there is a ItemUpdating going on, pressing Cancel at that screen causes this event NOT to occur.

In your case, of course ItemUpdated would be the best, but you need to make sure you block Event Firing while you do your operation (because ItemDeleting/-ed and ItemUpdating/-ed would trigger in loop) and also make sure you check for Content Approval being enabled and/or Versioning, as you need to CheckOut the actual file before manipulating it.

You could do an actual COPY of the document at the destination and run a DELETE on the Source (what about metadata - r u sure you get same properties on the destination?). If you plan to use it across SITES, do not use SPFile.MoveTo() as to my knowledge it only works on current subsite.

Have you considered also relying on Content Organizer to do it for you automatically and only set appropiate Metadata in your Handler?

2
  • Yes, I tried configuring the Content Organizer but without luck. I checked the CO settings and then created a rule to move a file based on metadata column, but it just doesnt work and I dont know how to troublshoot it.
    – Perplexed
    Apr 25, 2012 at 16:24
  • Disabling the eventfiring before my listitem update did the trick as it was this listitem update that was triggering the itemupdated event. On a separate note, does a file need to be checkedout in order to programmatically move it?
    – Perplexed
    Apr 25, 2012 at 16:30
0

Check this MSDN post - Using Event Receivers in SharePoint Foundation 2010.

In the above link, see the section 'Event Receiver Sequence' which specifies the order sequence for multiple event triggers. The sequence number binding as shown in Figure 1 (in above link) displays the SharePoint events pipeline and the execution order between sync & async events (*-ing or *-ed events).

For example, the 'SequenceNumber' would be specified in your event receiver's Elements.xml binding file (in this example you could add more event receivers and specify order by incrementing/decrementing the SequenceNumber) -

<Receiver>
<Name>FooEventReceiver1ItemAdded</Name>
<Type>ItemAdded</Type>
<Class>FooEvent.FooEventReceiver1</Class>
<SequenceNumber>10000</SequenceNumber>
<Synchronization>Synchronous</Synchronization>
</Receiver>
2
  • I changed the sequence numbers but I think the update handler may be fired by some code I have.
    – Perplexed
    Apr 25, 2012 at 16:28
  • yes.. you have to set the EventFiringEnabled property in your event handler in the try/finally blocks, similar to this: this.EventFiringEnabled = false; ..... this.EventFiringEnabled = true; Apr 25, 2012 at 18:43
-1

use static variables at top to handle this.. static variables are not re-initialized for instances of class.

bool itemAddedWasCalled = false;

protected void ItemUpdated(properties)
{
  if(!itemAddedWasCalled)
    {
      //Update code
    }
   else
    {
       itemAddedWasCalled = false;
    }
}

protected void ItemAdded(properties)
{
  //your code for itemAdded
  itemAddedWasCalled = true;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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