none
ItemDeleting event receivers on documents in a folder that is being deleted are not fired

    Question

  • When deleting a folder in a document library the ItemDeleting/ItemDeleted event receivers for all documents and folders contained in it are not fired even though they are being deleted. Only the event receivers of the folder being directly deleted is called.

    I can hardly imagine nobody has noticed this, but have found no information about it on the web at all. So I'm skeptical if I'm doing something wrong. Can anyone confirm or contradict my observations?

    As a background to our issues with this bevaiour: We have ItemDeleting event receivers on a document library needed to optionally restict deletion according to complex criterias, cleanup any references and add entries to a tracking list when a document is deleted. If these event receivers are not fired we have inconsistencies.

    Friday, December 27, 2013 12:26 PM

All replies

  • This is interesting. I have personally never ran into this situation and I am happy to execute quick test on my development environment. Before I do that I just want to know if you are disabling the event firing in anyway in your code. 

    If you are not doing that and if this is the default behavior only thing I can think of is that probably SP does not like to fire any event receiver on child items given there could be thousands of items under the folder. 

    If this is the behavior by design then what you can is instead of using the event receiver you can create your own custom delete item action which performs your logic.


    Amit

    Friday, December 27, 2013 2:04 PM
  • Hi drdany,

    Are you able to post any of the code for the event receiver so we can take a look into it?


    Alex

    Friday, December 27, 2013 2:05 PM
  • Sorry, but can't post all the event receiver code. It's like 1000s of propriety lines of code. But it really makes no difference to the issue here and can easily be reproduced. Just add an ItemDeleting event reciever doing nothing much and hook it to a document library. Then add documents inside a folder. Delete a document and check if the event receiver is called using debugger - should be fired. Now delete a folder with documents - event is fired for the folder, but not the documents contained which are also deleted.

    Tuesday, January 07, 2014 3:36 PM
  • This is interesting. I have personally never ran into this situation and I am happy to execute quick test on my development environment. Before I do that I just want to know if you are disabling the event firing in anyway in your code. 

    If you are not doing that and if this is the default behavior only thing I can think of is that probably SP does not like to fire any event receiver on child items given there could be thousands of items under the folder. 

    If this is the behavior by design then what you can is instead of using the event receiver you can create your own custom delete item action which performs your logic.


    Amit

    I'm not disabling any event receivers and have even explicitly enabled them before calling delete for test purposes. You will actually see the ItemDeleting event receiver is called for the folder being deleted. For the documents contained inside the folder no event receivers are fired.

    Also found out that when using bulk delete per ProcessBatchData no ItemDeleting event receivers are called either. Sounds like in SharePoint you can't count on event receivers (even synchronous) actually being fired:-(

    Still would be great if you could confirm my findings.

    Tuesday, January 07, 2014 3:44 PM