1

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?

3
  • I forgot to say I did check the DLL was there
    – Daniel Martinez
    Commented Nov 15, 2011 at 0:48
  • try to comment base.ItemDeleting(properties) Commented Nov 15, 2011 at 4:21
  • I tried it but the same error appears Commented Nov 16, 2011 at 14:39

2 Answers 2

1

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.

2
  • I'm using SP 07, so I don't have the RedirectUrl property Commented Nov 16, 2011 at 14:36
  • It could be little tricky for MOSS 2007. Please see my updated answer if that helps... Commented Nov 16, 2011 at 16:47
1

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.

1
  • I'm using SP 07, so I don't have CancelWithRedirectUrl in the SPEventReceiverStatus enumeration, thanks! Commented Nov 16, 2011 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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