Search This Blog

Wednesday, September 17, 2014

Custom Error Page in-SharePoint-2010

 when I try to delete an item from a list   i got  the error message as shown in below. The is typical  way ASP.NET Web Application throws the exception  to the user. Now in SharePoint 2010 we can redirect this error message to custom error page and we can show some fancy and useful information to user so that she/he understand very clearly about the error .

image
Now we are going to redirect the above error message to our custom error page.   In Custom List we are going to add an  event & handle the an Item Deleted event.
First Create a SharePoint 2010  Event Receiver project.
image
Now we have asked to select project deployment options either Sandbox or Farm.  I am going to  deploy this project as Farm Solution .
image
Now Choose the Type of Event Receiver and Item source. In our  case Source is Custom List and Type of Event Receiver is List Items.
image
Once you selected above settings click finish.  VS.NET 2010 will create Event Handlers for the events you selected in the above list.
image
Now add  Application page  item to the project.
image
Design your custom Error page using HTML  as shown below.
image
Now add the event handler code for ItemDeleteing as Shown below.
   1:  using System;


   2:  using System.Security.Permissions;


   3:  using Microsoft.SharePoint;


   4:  using Microsoft.SharePoint.Security;


   5:  using Microsoft.SharePoint.Utilities;


   6:  using Microsoft.SharePoint.Workflow;


   7:   


   8:  namespace SreeniItemDeleteErrorMessage.EventReceiver1


   9:  {


  10:      /// <summary>


  11:      /// List Item Events


  12:      /// </summary>


  13:      public class EventReceiver1 : SPItemEventReceiver


  14:      {


  15:         /// <summary>


  16:         /// An item is being deleted.


  17:         /// </summary>


  18:         public override void ItemDeleting(SPItemEventProperties properties)


  19:         {


  20:             base.ItemDeleting(properties);


  21:             properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;


  22:             properties.RedirectUrl = "/_Layouts/SreeniItemDeleteErrorMessage/ItemDelete.aspx";


  23:         }


  24:   


  25:   


  26:      }


  27:  }



Now Build ,deploy & test  the solution (Hit F5). Now go to any Custom list and try to delete an item.


image


now you will get this Custom Error message.


image


No comments:

Post a Comment