SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a SharePoint 2007 list with an event receiver, its logic is very simple:

public override void ItemDeleting(SPItemEventProperties properties)
        //Base event

        //Ready 2 use variables
        bool cancel = true;

        //If the permissions are valid
        if (validPermissions(properties))
            cancel = false;
            cancel = true;

        properties.ErrorMessage = "You cannot delete the item, please verify your permissions";
        properties.Cancel = cancel;
        SPUtility.Redirect(properties.OpenWeb().Url + "/Pages/AssessmentCatalog.aspx", SPRedirectFlags.Static, HttpContext.Current);


When deleting an item and the event gets canceled (I mean the boolean becomes true) I get an error message:

Server Error 404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

The URL is the following:


The thing is, it only happens when the event gets canceled, otherwise it deletes the item correctly and I cannot figure out why is this happening.

Can you please help me?

share|improve this question

migrated from Nov 15 '11 at 1:04

This question came from our site for professional and enthusiast programmers.

I forgot to say I did check the DLL was there – Daniel Martinez Nov 15 '11 at 0:48
try to comment base.ItemDeleting(properties) – Amit Kumawat Nov 15 '11 at 4:21
I tried it but the same error appears – Daniel Martinez Nov 16 '11 at 14:39
up vote 1 down vote accepted

Assuming you are using SharePoint 2010. You need to set RedirectUrl property and sets the status= CancelWitharedirectUrl. SharePoint should handle redirect automatically as documented here

Update for MOSS 2007 HttpContext.Current parameter in Redirect method is null in your code. Others have found a workaround for that:

Also try setting the properties.Status = SPEventReceiverStatus.CancelNoError.

if you are trying to show a message in the new page, you may have to pass the message key (or message itself) as a query string parameter.

share|improve this answer
I'm using SP 07, so I don't have the RedirectUrl property – Daniel Martinez Nov 16 '11 at 14:36
It could be little tricky for MOSS 2007. Please see my updated answer if that helps... – Ashish Patel Nov 16 '11 at 16:47
Thank you very much! That did solve the problem! – Daniel Martinez Nov 16 '11 at 19:59

Generally I think your problem, you use not correct redirection, use this:

properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
properties.RedirectUrl = "/Pages/AssessmentCatalog.aspx"";

I dont think this is your main problem, but properties.OpenWeb().Url could return not root url, use SPSite.Url instead. The method OpenWeb() returns the url which was provided when object was created. Example is:

Using(SPSite site = new SPSite("http://host/subweb"))
    Using(SPWeb web = site.OpenWeb())
        string url = web.Url; //http://host/subweb

Use properties.OpenSite().Url instead.

share|improve this answer
I'm using SP 07, so I don't have CancelWithRedirectUrl in the SPEventReceiverStatus enumeration, thanks! – Daniel Martinez Nov 16 '11 at 14:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.