Monday, October 13, 2008

How to prevent code from crashing when adding an event handler to a documentlibrary.

I had the follwing issue:

I added an event handler to a document library. Every time i added a new document the eventhandler would run fine but when a user had entered metedata againt a doucument and pressed ok, sharepoint would crash. The reason behind this was, I was tring to update an item when there was already an update in progress. I fixed the issue by running the follwing update code.

DisableEventFiring();
item.SystemUpdate(false);
EnableEventFiring();

No comments: