SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

share|improve this question
up vote 1 down vote accepted

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

share|improve this answer
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 '11 at 19:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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