01
May

Recently I was tasked with writing an event-handler that basically increments a unique number and assigns this to the ‘Document Number’ list item in a document library once a document is added.

Sounds reasonable yes? Usually it is simply a case of adding code to the itemAdded / ItemAdding or ItemUpdate / ItemUpdating events of the list, getting a new number and assigning it to the ‘document number’ column in the list.

The problem is when Check in & Checkout is enabled on the document library. When this is enabled, a lot of strange and wonderful things happen, specifically in regard to how the events fire. I’ve basically debugged the sequence and it’s shown below:

Standard Document Library, no Check In or Check Out turned on.

New document from the ‘New’ menu item

  • ItemAdding
  • ItemAdded

Saving document using the same name as an existing document

  • ItemUpdating
  • ItemUpdated

Uploading a new document using the ‘upload’ menu item

  • ItemUpdating
  • ItemUpdated
  • (Prompted user for document properties)
  • ItemUpdating
  • ItemUpdated

Multiple uploads. 1 new document, 1 existing. NB, No Doc Properties window is shown during the upload.

  • ItemUpdating
  • ItemUpdated
  • ItemAdding
  • ItemAdded

Multiple uploads, 2 existing documents in the document library

  • ItemUpdating
  • ItemUpdating
  • ItemUpdated
  • ItemUpdated

 

Now lets turn on Check In and Check Out on the document library.


Check In turned on. New document

  • ItemAdding
  • ItemAdded
  • ItemCheckingOut
  • ItemCheckedOut
  • At this point your prompted to check in.
  • ItemUpdating
  • ItemUpdated
  • ItemUpdating
  • ItemCheckingIn
  • ItemUpdated
  • ItemCheckedIn

New document, Check In turned on, but user didn’t check in the document.

  • ItemAdding
  • ItemAdded
  • ItemCheckingOut
  • ItemCheckedOut

User proceeds to check in the document that was added in the previous step.

  • ItemUpdating
  • ItemUpdated
  • ItemUpdating
  • ItemCheckingIn
  • ItemUpdated
  • ItemCheckedIn

Upload single document

  • ItemAdding
  • ItemAdded
  • Prompted for doc properties!
  • ItemUpdating
  • ItemUpdating
  • ItemUpdated
  • ItemCheckingIn
  • ItemUpdated

2 new documents uploaded

  • ItemAdding
  • ItemAdding
  • ItemAdded
  • ItemAdded

2 documents uploaded in previous step. Need checked in. Events fire once per document.

  • ItemUpdating
  • ItemCheckingIn
  • ItemUpdated
  • ItemCheckedIn

1 document dragged in from Explorer View

  • ItemAdding
  • ItemAdded

Multiple documents dragged in from Explorer View

  • ItemAdding – doc1
  • ItemAdded
  • ItemAdding – doc2
  • ItemAdded

Checking in Explorer Documents from previous step (runs per document)

  • ItemUpdating
  • ItemCheckingIn
  • ItemUpdated
  • ItemCheckedIn

 

So what’s the bottom line? Ultimately the event handler should be tailored to determine if Check In/Checkout is enabled. If Check In/ Check Out isn’t enabled, use Adding/Added/Updating/Updated. If it is, use the Checked In handler. I haven’t come across a technique to determine through the properties item if check in is turned on. I suspect I’d have to access the list and go from there.

VN:F [1.9.2_1090]
Rating: 10.0/10 (2 votes cast)
VN:F [1.9.2_1090]
Rating: +2 (from 2 votes)
Event Handling, with ‘Check In’ enabled., 10.0 out of 10 based on 2 ratings

Comments are closed.

-->