views:

158

answers:

1

In SharePoint, when an item is first added to a document library, it fires the ItemAdded and ItemAdding events as expected. And if you upload the same filename to update the existing file, it will fire off ItemUpdated and ItemUpdating events, likewise as expected. However, I have been unsuccessful at determining whether this kind of action has actually occurred or not. Or, more specifically, I am entirely unable to differentiate between the following:

  • An item is updated because someone uploaded a new file but did nothing to any of the form fields.
  • An item is updated because someone hit "OK" but did nothing to any of the form fields.

Is there actually a way to distinguish these kinds of updates? There appears to be nothing in event properties that contains this information, nor in the version history for both the list item and the file itself. I have even tried comparing the files themselves via OpenBinary(), but in both mentioned cases I still get the same result. Thank you in advance for any help!

+2  A: 

I went through this same problem just over 2 years ago. The way I implemented it was by looking at all the fields in the before and after properties for both event types and some of the more obscure fields were different depending on the kind of event.

Unfortunately I don't have access to that code any more so I can't give you the name of the field. Just dump all the before and after properties and play around with it.

Painful, you'd think there would be an easier way. I had hoped that during the first upload the Before Properties would be null or empty, but no such luck.

Muhimbi
At first when I tried this, I didn't find anything that did successfully distinguish anything, but that's because I only logged things which were in AfterProperties and either had changed from Before, or not been present. I added an extra log for things which are in Before, but not in After. Sure enough, the following were consistently "missing" in the multitude of different upload methods I use: vti_rtag, vti_etag, vti_replid, vti_docstoreversion, ti_docstoretype. This had the unfortunate side effect of teaching me that update events fire twice at a time, but what works is what works. Thanks!
ccomet
Those field names sound familiar. Make sure you create some kind of automated test for this as it is undocumented and not unlikely to change between service packs / SharePoint versions.
Muhimbi