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 am using the ItemDeleting event receiver to prevent users from deleting items in a Task List.

Currently, my code looks like:

        if (properties.ListTitle == "Project Intake Tasks")
        {
            properties.Cancel = true;

        }

And this works but it results in a "<nativehr>0x81020089</nativehr><nativestack></nativestack>An event receiver has canceled the request. " error when a user tries to delete a task from the Task Item Edit page. Is there a way to get rid of this error or to grey out the Delete Item button in the Task Item Edit page?

Note: I tried to set custom permissions for the list but could not find a specific "Delete Item" permission level as talked about here http://office.microsoft.com/en-us/windows-sharepoint-services-help/permission-levels-and-permissions-HA010100149.aspx.

Is there a specific Item Delete permission level for lists that I just can't find?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

It looks like if you go into Site Settings > Site Permissions > Edit > Permission Levels > Add a Permission Level you can create a custom permission level that lets user do everything but delete an item. Then apply that custom permission level to all the users and groups of the task list.

share|improve this answer
    
Yep stackoverflow.com/a/5541872/98933 –  Kit Menke May 1 '12 at 21:47
add comment

A couple of things:

You can't create the permission level for a single list, but you have to create that a Site Collection level as @Meyer describes (usually by making a copy of Contribute and remove Delete Item), then you can break permission inheritance on that specific list and remove Contribute from people/groups and add your custom permission level instead.

You may still want to keep the event receiver in place to protect against site collection admins (and changed permissions)

If you don't want your event receiver to show a nasty error, then you have the option of setting properties.Status to SPEventReceiverStatus.CancelNoError instead of setting Cancel this will cancel the action but not show anything to the user (which may confuse them very much) or if you're running 2010 then you can set the Status to CancelWithRedirectUrl and specify a page with a nice error message as RedirectUrl

If you only want to protect a single list then it's a lot better to only register your event receiver to that single list instead of all lists of that type.

share|improve this answer
add comment

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.