I have a document library with a ItemAdding event receiver registered to it that looks for whether a folder has been added and if so, cancels the folder creation.

This works fine in the GUI. However, when in Explorer view, although the event receiver fires, the event is not cancelled.

I have ran the debugger in Visual Studio and the below two lines are definitely being executed, so I can't understand why the event is not being cancelled?

properties.Status = SPEventReceiverStatus.CancelWithError; 
properties.ErrorMessage = "You cannot create folders here.";   

1 Answer 1


You also need to set

properties.Cancel = true;

  • I'll give this a try. But do you know why my code would work when in the browser and not when in Explorer?
    – Submits
    May 13, 2015 at 11:32
  • It seems the Cancel property is obsolete. The Status property should be used instead, so my code is up to date. msdn.microsoft.com/en-us/library/…
    – Submits
    May 13, 2015 at 11:38
  • The issue is that when you add item to document library, the event receiver is triggered multiple times, now it depends where have you placed your CancelWithError statement May 13, 2015 at 11:40
  • I have run the debugger and the event receiver only fires once, as it should.
    – Submits
    May 13, 2015 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.