If a user uploads multiple documents in document library, is there any way we know in the event receiver that these belong to the same up loader and not other user who also might upload some document at that time. The reason for this is we want to assign a field called documentID with the same ID for all the 3 documents is it feasible?
2 Answers
Since event handlers fire for each item I don't think it is possible to know that they all were uploaded in the same upload unless you include some extra fields to track things. You could add a field that records the upload time and then if a item is in the event handler and there is another item with the same user created and time uploaded then you would assign the same id. Something like this is the only way I can see to accomplish this.
You could start your code on the "added" event and then by looking at the upload location, created by and time fields make the assumption that this must have been the same activity.
On each event have the code write to a simple logging list item which records info on each upload event. The list item could have a title field ("whatever?"), a field for "filetobeupdated" and a custom field recording "user + location + timestamp".
Then on this list item have another event receiver, on updated, to parse the list items looking for those with similar custom fields & timestamp. This would give you a reference to the files that need to have the custom docid written to. You could then clear the logging list afterwards to keep it from becoming tricky to parse.