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 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

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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?

share|improve this answer
    
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 '12 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 '12 at 16:30

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>
share|improve this answer
    
I changed the sequence numbers but I think the update handler may be fired by some code I have. –  Perplexed Apr 25 '12 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; –  Supriyo SB Chatterjee Apr 25 '12 at 18:43

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.