Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top