Customized error page in Sharepoint

In SharePoint there is not any functionality for displaying our customized error page.Like if for data validation in event/item handler we use

properties.ErrorMessage = “Opps… Not allowed”;
properties.Cancel = true;

And validation message displayed in SharePoint error Page which looks error in application.
But with this Context you can use to redirect to any of your custom or any out of the box Page.

SPUtility.Redirect(Url, SPRedirectFlags.Default, current);

Here current is nothing but the HTTPContext object that u create in the constructor of the Event handler class


4 thoughts on “Customized error page in Sharepoint

Add yours

  1. Hi Chanakya,

    I am struglling to make it work…

    I would like to use this in itemdeleting event reciever for a document library with in sharepoint MOSS 2007.. I have the following code as constructor

    public class ItemDelete:SPItemEventReceiver
    private HttpContext currentContext = null;
    public ItemDelete():base()
    if (null != HttpContext.Current)
    currentContext = HttpContext.Current;

    and i have used the ccurrentContext in my event as

    public override void ItemDeleting(SPItemEventProperties properties)
    if (–my–condition–)
    SPUtility.Redirect(“”, SPRedirectFlags.Default, currentContext);

    if i run this program the delete event is not triggering at all and redirection is also not happening.. can you please tell me what is that i am missing.

    much appriciate your response.. thanks.

    1. Hi Naresh,

      Your code seems to be perfect.

      Since you are saying the delete event is not triggering check whether your event handler registered properly (Check your feature & element file).

      Also try to debug the code. This way you can make sure your event handler is registered.

      Also check whether your HttpContext object is having some value after the execution of the constructor or still its null.

  2. HI Chanakya,

    thanks for your time.. i was unable to get it done by using this method.. after several attempts i end up with an alternative solution, where i added some redirection JavaScript in ERROR.HTM page to redirect to my custom error page based on URL referrer., in that way infact i can avoid the users to see the custom error page too, by adding an another javascript redirection to point back to actual library so in over all it looks like a JavaScript alert on item delete event receiver.

    Thanks again.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Create a website or blog at

Up ↑

%d bloggers like this: