SharePoint 2010 - Event Receiver - Redirect URL not working

1.5k Views Asked by At

I have a problem with an event receiver, I created in Visual Studio. In a special case, I want to redirect to a site. But the event receiver is showing only the error page with the error "An event receiver has canceled the request." This message I can modify with the properties.ErrorMessage property, but I want to redirect and NO error message! Here's my code:

if (NoErrors == false)
{

                    properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
                    properties.RedirectUrl = SPUrlUtility.CombineUrl(properties.WebUrl, @"MyEditForm.aspx?"
                                            + "Mode=Upload"
                                            + "&CheckInComment="
                                            + "&ID=" + properties.ListItem.ID
                                            + "&RootFolder=%2Fsites%2FSuppliers%2FLists%2FDocument%20Center"
                                            + "&IsDlg=1"
                                            + "&ContentTypeId=" + properties.ListItem.ContentType.Id
                                            + "&IsDlg=1"
                                            + "&error=" + AllErrorsText);
}

What I'm doing wrong? Can anybody help? Thanks in advance.

Edit: Solution: Use a relative URL and no special characters in the error variable "AllErrorsText".

string TestUrl = "MyEditForm.aspx?"
                 + "Mode=Upload"
                 + "&CheckInComment="
                 + "&ID=" + properties.ListItem.ID
                 + "&RootFolder=%2Fsites%2FSuppliers%2FLists%2FDocument%20Center"
                 + "&IsDlg=1"
                 + "&ContentTypeId=" + properties.ListItem.ContentType.Id
                 + "&IsDlg=1"
                 + "&error=" + AllErrorsTextUrl;
properties.RedirectUrl = TestUrl;
properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
1

There are 1 best solutions below

0
On BEST ANSWER

I found the solution by myself:

Use a relative URL and no special characters in the error variable "AllErrorsText".

    string TestUrl = "MyEditForm.aspx?"
                 + "Mode=Upload"
                 + "&CheckInComment="
                 + "&ID=" + properties.ListItem.ID
                 + "&RootFolder=%2Fsites%2FSuppliers%2FLists%2FDocument%20Center"
                 + "&IsDlg=1"
                 + "&ContentTypeId=" + properties.ListItem.ContentType.Id
                 + "&IsDlg=1"
                 + "&error=" + AllErrorsTextUrl;
properties.RedirectUrl = TestUrl;
properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;