1

I want users to upload the .doc files only in the document library.

To do so, I have developed an event receiver in Visual Studio 2010.

My code is as follows:

public override void ItemAdding(SPItemEventProperties properties)
{
       try
       {

           base.ItemAdding(properties);
           EventFiringEnabled = false;

           if (!properties.AfterUrl.EndsWith("doc"))
           {
               properties.ErrorMessage = "You are allowed to updload only .doc files";
               properties.Status = SPEventReceiverStatus.CancelWithError;
               properties.Cancel = true;

           }
       }
       catch (Exception ex)
       {
           properties.Status = SPEventReceiverStatus.CancelWithError;
           properties.ErrorMessage = ex.Message.ToString();
           properties.Cancel = true;
       }

}

The code is referred from this example.

My problem is that while I am uploading non-doc files it is preventing but with the system error message not the user friendly as defined in properties.ErrorMessage.

How do I solve this?

Please help.

Mohemmad K
  • 809
  • 7
  • 33
  • 74

1 Answers1

0

I used the same code you have provided in your question, I get custom error message displayed as shown in below image -

enter image description here

Please provide details of the error you are getting.

Amit Thakkar
  • 356
  • 2
  • 6
  • 1
    Open your web.config file ["C:\inetpub\wwwroot\wss\VirtualDirectories\YourAppPort\web.config"] and set CustomError = "On" and then check. – Amit Thakkar Jul 24 '13 at 11:49
  • Set CallStack="false" in web.config file; give it a try. – Amit Thakkar Jul 24 '13 at 12:36
  • Created new solution and rewrote the code but still the same error occurs... @Amit Thakkar – Mohemmad K Jul 24 '13 at 12:36
  • 1
    There is nothing wrong with your solution, try setting CallStack="false" in web.config file; this should work. But make sure you are applying web.config changes to your application's web.config file. – Amit Thakkar Jul 24 '13 at 12:37
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/34070/discussion-between-riyaz-kalva-and-amit-thakkar) – Mohemmad K Jul 24 '13 at 12:39