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'm trying to create a sandboxed event handler feature to handle the OnDeleting event of a task list in SharePoint 2010. I followed Microsoft's instructions. When I deploy the event receiver from Visual Studio, I get an "Attach Security Warning." I select Attach, and the correct SharePoint site opens in the browser.

However, when I navigate to the Tasks list and delete an item, it doesn't tell me "deleting items is not supported" like it should. It just shows the normal delete confirmation message.

Any suggestions about what I might be doing wrong?

Edited to add elements.xml as requested in comments:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListTemplateId="107">
  <Receiver>
    <Name>EventReceiver1ItemDeleting</Name>
    <Type>ItemDeleting</Type>
    <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
    <Class>DeletingEventReceiver_TasksTest.EventReceiver1.EventReceiver1</Class>
    <SequenceNumber>10000</SequenceNumber>
  </Receiver>
  </Receivers>
</Elements>

Edited to add EventReceiver1.cs code:

using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;

namespace DeletingEventReceiver_TasksTest.EventReceiver1
{
/// <summary>
/// List Item Events
/// </summary>
public class EventReceiver1 : SPItemEventReceiver
{
   /// <summary>
   /// An item is being deleted.
   /// </summary>
   public override void ItemDeleting(SPItemEventProperties properties)
   {
       base.ItemDeleting(properties);
       properties.Cancel = true;
       properties.ErrorMessage = "Deleting items from " + properties.RelativeWebUrl + " is not supported.";
   }
}
}
share|improve this question
1  
SharePoint will always show the normal delete confirmation message. It only after you select OK that OnDeleting is called. Have you tried to go further? –  Per Jakobsen Mar 20 '12 at 16:53
    
What does it do after showing that message? Does it still delete the item? Could you post your Elemenst.xml as well as some details about the list you are testing in? –  Robert Kaucher Mar 20 '12 at 17:34
    
I clicked OK at the confirmation message and the item deleted as normal. The list is the default tasks list that comes with the Team Site template. I've posted the elements.xml contents above. –  LCountee Mar 20 '12 at 18:54
1  
Can we also see the code for EventReceiver1ItemDeleting? Make sure you don't call the base method at then end as it'll set the status to continue –  Per Jakobsen Mar 20 '12 at 19:11
    
What happens in VisualStudio when you try to set a break point? I assume you are deleting items from the default Tasks list? I had an issue like this quite recently and I honestly think I may have selected the wrong List Type when creating the event receiver and I changed ListTemplateId to ListUrl so I cannot be certain. The next day I started over with a new project and made certain I selected a task list and everything worked. –  Robert Kaucher Mar 21 '12 at 1:41

1 Answer 1

up vote 1 down vote accepted

Verify the event receiver is registered

$web = Get-SPWeb "http://site"
$list = $web.Lists["TargetList"]
Write-Host $list.EventReceivers.Count

Also verify if you added safe control entries for the event receiver namespace. See this on how to add safe controls in vs2010. You most likely do not have any safe control entries.

share|improve this answer
    
Thanks, your PowerShell script showed me that the event receiver was not registered. That led me to realize that I had not deployed the feature correctly as shown here. –  LCountee Mar 21 '12 at 13:34

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.