If you would like to discuss anything, please contact me via email: Howard.Bayliss@sequence.co.uk

Friday, May 20, 2011

SharePoint "Item does not exist. It may have been deleted by another user"

I'd created an Event Receiver to handle the ItemDeleted event. I'd assigned this to a ContentType, which was then added to a Picture Library.

Click the image below to see what the code looked like. Initially, this seemed to work prefectly. (I'm using an image to show the code so that the text formatting is unmangled and read-able).



However, if I selected multiple pictures in the library and then clicked the "Delete" option from the library's menu, an unhandled exception was thrown which read "Item does not exist. It may have been deleted by another user".

I discovered the fix for this, which was to re-arrange the "try" blocks in my code. So instead of having the try-catch block surrounded by the try-finally block, I switched them so that the try-catch block is surrounded by the try-finally block.

I suspect the error was being generated because of a thread-timing issue, since (when the error occurred) the debugger wouldn't hit any breaks points in the code.

The re-worked code is shown below. I realise I could also reduce the code by using a try-catch-finally block, rather than 2 try blocks.

No comments:

Post a Comment