0

I have a SPItemEventReciever that works perfectly when I update a list item via the sharepoint web interface but does not fire when updated via the object model.

The event reciever is deployed via a feature

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListTemplateId="10025">
  <Receiver>
    <Name>RequestLogEventRecieverItemAdded</Name>
    <Type>ItemAdded</Type>
    <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
    <Class>TimeOffRequest.SharePoint.RequestLogEventReciever.RequestLogEventReciever</Class>
    <SequenceNumber>10001</SequenceNumber>
  </Receiver>
  <Receiver>
    <Name>RequestLogEventRecieverItemUpdated</Name>
    <Type>ItemUpdated</Type>
    <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
    <Class>TimeOffRequest.SharePoint.RequestLogEventReciever.RequestLogEventReciever</Class>
    <SequenceNumber>10000</SequenceNumber>
  </Receiver>
  <Receiver>
    <Name>RequestLogEventRecieverItemDeleted</Name>
    <Type>ItemDeleted</Type>
    <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
    <Class>TimeOffRequest.SharePoint.RequestLogEventReciever.RequestLogEventReciever</Class>
    <SequenceNumber>10002</SequenceNumber>
  </Receiver>
  </Receivers>
</Elements>

My list definition:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Do not change the value of the Name attribute below. If it does not match the folder name of the List project item, an error will occur when the project is run. -->
<ListTemplate
    Name="Time Off Request Log"
    Type="10025"
    BaseType="0"
    OnQuickLaunch="FALSE"
    SecurityBits="11"
    Sequence="410"
    DisplayName="Time Off Request Log"
    Description="My List Definition"
    Image="/_layouts/images/itgen.png"/>
</Elements>

The code I am running:

var requestList = SPContext.Current.Web.Lists["Request Log"];
var item = requestList.Items.Add();
item["Title"] = "Test";

item.Update();

I have the event sending an email on ItemUpdated. I get the email when I update via the SharePoint web interface (and my breakpoint is hit). I do not get it when I execute the code above. The new item (with a title of "Test") is added to the list, but no email is sent and my breakpoint in ItemUpdated is not hit.

If it maters, this code is in a click event for a button that is on very simple webpart (only the button).

  • Is the ItemAdded event firing? And is it possible that there's logic in the event receiver to require something other than just the title to change? – lgaud Oct 8 '13 at 16:18
0

I think your custom code which is behind your Button Click only fires ItemAdded event, not ItemUpdated. So you have two chances:

  1. Put your code block which is in ItemUpdated inside the ItemAdded method too.
  2. In your Button Click code, first add the item, then explicitly Update the item again.
  • Grr, so item update after items.add is really just adding the item....makes sense now I guess. :) So item.Update(); item.Update(); fixes my issue. – Jon Price Oct 8 '13 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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