Thursday, February 24, 2011

Custom error message in SharePoint 2010 + Feature Receiver

In SharePoint 2007 there was no way to redirect to custom error page when you use event receivers, if you try also it redirects to default out of the box blue-white error page

But in SharePoint 2010 there are some properties by using this you can redirect to custom error page

public override void ItemAdding(SPItemEventProperties properties)

{
base.ItemAdding(properties);
string tite = properties.AfterProperties[“title”].ToString();
if(tite.Contains(“RSM”))
{
properties.Cancel = true;
properties.Status = SPEventRecieverStatus.CancelWithRedirectUrl;
Properties.RedirectUrl = “/_layouts/CustomError.aspx?errormessage=bang...don't use RSM...I hate RSM”;
}
}

Limitations.

This works only for synchorounous events like Itemadding, deleting etc...
Works only for browser based clients not with outlook.

1 comment:

  1. It works only for system account. how to use other sharepoint users.

    ReplyDelete