Friday, July 17, 2009

Item Adding Event firing on a move

I have an ItemAdding event handler that generates a unique id for a document across document libraries and sites. The event handler is attached to the base content type.

All was going well until I started moving documents. A move fires the ItemAdding event, which recreates a new number for a document.

As the FileMoving and FileMoved event handlers are useless, I needed away to tell if the ItemAdding event is a new document or a moved document.

I eventually worked out a way...In the SPItemEventProperties object is a property named ListItemId. This will be 0 for new items, and a number greater then 0 for an existing item (it is in fact the ID of the record in the existing document library).