Monday, July 2, 2012

sharepoint event handler redirect page

Here is the one more requirement to redirect user from event handler.

You can redirect user to a custom message page with code.

Here is the code for that.


/// 
       /// An item is being added.
       /// 
        public override void ItemAdding(SPItemEventProperties properties)
        {
            base.ItemAdding(properties);
            
            // Any condition 
            if (properties.ListItem["Manager"] != SPContext.Current.Web.CurrentUser.LoginName)
            {
            
                // Set the status property to CancelWithRedirectUrl this tells the event handler to cancel the operation
                properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
                
                // Get the application page generic with SPUtility 
                properties.RedirectUrl = SPUtility.GetGenericSetupPath("/MyProj/MyPage.aspx");

            }
        }




Thank you !!!



No comments:

Post a Comment