Since you are still in the ADDING event, you could cancel the event by setting the appropiate properties on the event SPItemEventProperties object.
For pre SP 2010:
Use the Cancel property. This will report an error message to the user - afaik there is no way to avoid it, but you can still customize the message.
public virtual void ItemAdding(SPItemEventProperties properties)
// Your logic here....
properties.Cancel = true;
properties.ErrorMessage = "A custom error message.";
For post 2010: Cancel is now deprecated, so use the Status property instead. This is an enum - to cancell the event you have 3 alternatives (taken from msdn):
- A value of CancelNoError means to silently cancel the request as if the request has succeeded.
- A value of CancelWithError means to cancel the request with the error message specified in ErrorMessage.
- A value of CancelWithRedirectUrl means to cancel the request and redirect to the URL specified in RedirectUrl.
Just keep in mind that CancelNoError seems to give problem when used on a document library (the user gets redirect to a file not found page). If this is your case your best bet is to use cancelWithError or CancelWithRedirectUrl (wich could redirect the user to a page explaining why the file adding process was "cancelled")