Pergunta

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

Foi útil?

Solução

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?

Outras dicas

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>

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;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top