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 was using a workflow to change file names to some text and the SP ID, but this has caused issues because the workflows can often take several minutes to complete. I would like to do this during ItemAdding, but I'm 99.999% sure this isn't possible since the ID probably isn't assigned until the document is uploaded. I think I might use ItemAdded, but I don't know how long that might take to kick off. Are either of these reasonable ideas?

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

This sort of task is more suited to an event receiver. The itemAdded approach will certainly give you access to the ID. An event receiver does not have the typical delay you see with Workflows, it fires right away.

One issue you can experience with ItemAdded events is that they run asynchronously. What this means is that the control is returned to the UI while the Event Receiver is kicked off. This can cause situation where the event receiver is not quite done processing before the display returns to the user, and they won't see the updated values until they refresh the page.

The solution to this is to set the mode for the ItemAdded event receiver to Synchronous in the Elements.xml file for the event receiver using :

  <Synchronization>Synchronous</Synchronization>

In context:

<Receiver>
  <Name>Test_ListEventReceiversItemAdded</Name>
  <Type>ItemAdded</Type>
  <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
  <Class>TestEventReceivers.Test_ListEventReceivers.Test_ListEventReceivers</Class>
  <Synchronization>Synchronous</Synchronization>
  <SequenceNumber>10000</SequenceNumber>
</Receiver>

With the Synchronous mode, the display won't return to the user until the processing is complete.

share|improve this answer
2  
The ID is not present in the ItemAdding AfterProperties (the file hasn't been added to the library yet) –  MdMazzotti Mar 11 at 19:20
    
Thanks for clarifying that. I will update my response (and not have to run a test. :) –  lwbecker2 Mar 11 at 19:25
    
Appreciate your help! I can't + rep yet, but I will mark as answer. –  user3362735 Mar 11 at 20:23
add comment

You can do that in ItemAdded and make it synchronous so it will fire and execute in the same thread after ItemAdding is finished.

You can make an after event syncronous when you define it in your solution, or you can do it with code or PowerShell script.

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.