0
votes

I'm trying to get create an ItemUpdating event that checks for some potentials issues in a couple of lists. However the item event does not seem to be triggering at all, even debugging the call to ItemUpdating( .. ) does not work, it is as if the method is never called.

Event code:

namespace MyEvent.EventReceiver1
{
    public class EventReceiver1 : SPItemEventReceiver
    {
       public override void ItemUpdating(SPItemEventProperties properties)
       {

           base.ItemUpdating(properties);

           // ... my code testing column BeforeProperties vs AfterProperties
           if (properties.ListTitle == "My List")
           {

               if (properties.BeforeProperties["some field"] != properties.AfterProperties["some field"])
               {
                   properties.Cancel = true;
                   properties.ErrorMessage = "Please do not alter some field in my list";
               }
           }
       }
    }
}

If I debug "public override void ItemUpdating()" it never fires when updating a list- rather it is "My List" or not. So my check is never run even if "My List" updates an item.

My elements.xml:

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

Note that this event receiver is quite a bit more complex in reality.. it fires on several different events with some fairly in-depth functionality. Everything else in the feature works fine except the above ItemUpdating and ItemDeleting methods.

1
Can you check your deployed elements.xml and make sure that <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly> actually shows your assembly?Nemanja Trifunovic
You could use http://spm.codeplex.com and check, is it right deployed in the SPMishaU

1 Answers

0
votes

Was your "My List" created using the out of the box Custom List? Your event receiver will only process those types of lists when your Receivers element is defined as ListTemplateId="100". To test your event receiver, try creating a new Custom List and check if the event fires when you update an item.

If this event receiver is only intended for one specific list, you could change your element definition to:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListUrl="Lists/MyListUrl">
      <Receiver>
        <Name>EventReceiver1ItemUpdating</Name>
        <Type>ItemUpdating</Type>
        <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
        <Class>MyEvent.EventReceiver1.EventReceiver1</Class>
        <SequenceNumber>10000</SequenceNumber>
      </Receiver>
  </Receivers>
</Elements>