Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

public override void ItemDeleting(SPItemEventProperties properties)
    {
        //Base event
        base.ItemDeleting(properties);

        //Ready 2 use variables
        bool cancel = true;

        //If the permissions are valid
        if (validPermissions(properties))
            cancel = false;
        else
            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:

http://SOMESITESURL/_vti_bin/owssvr.dll?CS=65001&Cmd=Delete&List={BDCE6E94-F630-4C4A-B631-7D53C8568E61}&ID=45&NextUsing=SOMESITEURL

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 stackoverflow.com 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

2 Answers 2

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 http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spitemeventproperties_members.aspx

Update for MOSS 2007 HttpContext.Current parameter in Redirect method is null in your code. Others have found a workaround for that: http://www.sharepointkings.com/2008/05/httpcontext-in-eventhandler.html

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

 
discard

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.