Here is my code. It works but also throws following error.

public override void ItemAdding(SPItemEventProperties properties)
    if (ValidFile(properties) == false)
        properties.ErrorMessage = "File size cannot be greater than 1MB";
        properties.Cancel = true;

Server Error in '/' Application.

0x81020089File size cannot be greater than 1MB Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: 0x81020089File size cannot be greater than 1MB

Source Error:

1 Answer 1


It's normal that you have this error displaying. The file you are trying to upload does not meet validation so an exception is generated on the server (by setting ErrorMessage and Cancel properties)

the thing is that it's a normal behavior and it would look pretty normal if you hadn't activated ASP.NET exceptions but let the SharePoint one. It would show in a more user-friendly way that the file does not meet validation.


and to complete the answer, you can set up back the SHarePoint errors in the web.config with CustomErrors Mode="On" and SafeMode Callstack="false"

Hope it helps

  • Thanks a bunch. Yes, you are right. I had to turn them off and now it's looks much better. and the error screen looks good as well.
    – David Mike
    Jul 11, 2011 at 19:47

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.