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 created an event receiver in Visual Studio to handle three events in a form library: ItemAdding, ItemUpdating, and ItemDeleting.

ItemUpdating and ItemDeleting work as expected when debugging, but ItemAdding does not seem to fire at all. I put a break point within the ItemAdding handler, but it is never reached.

Suggestions?

Editing to add code:

Elements.xml:

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

  </Receivers>
</Elements>

EventReceiver1.cs:

namespace myAddUpdateDeleteHandler.EventReceiver1
{
/// <summary>
/// List Item Events
/// </summary>
public class EventReceiver1 : SPItemEventReceiver
{
    string strReportsListName = "Timesheet Reports Test";
    string strTimesheetLibraryName = "Form Library Test";

   /// <summary>
   /// An item is being added.
   /// </summary>
   public override void ItemAdding(SPItemEventProperties properties)
   {
       base.ItemAdding(properties);

       using (SPSite site = new SPSite(properties.WebUrl))
       {
           using (SPWeb web = site.OpenWeb())
           {
               SPList reportList = web.Lists[strReportsListName];
               SPList timesheetLibrary = web.Lists[strTimesheetLibraryName];

               #region add item to reports list, including various values from forms library
               SPListItemCollection listItems = web.Lists[strReportsListName].Items;
               string strUsername = properties.AfterProperties["LinkTitle"].ToString();

               // add Monday
               SPListItem item = listItems.Add();
               item["LinkTitle"] = strUsername; //username
               item["First_x0020_Name"] = properties.AfterProperties["First_x0020_Name"];
               item["Last_x0020_Name"] = properties.AfterProperties["Last_x0020_Name"];
               item["Date"] = properties.AfterProperties["Week_x0020_Starting_x0020_Monday"];
               item["Month"] = properties.AfterProperties["Monday_x0020_Month"];
               item["Year"] = properties.AfterProperties["Year"];
               item["Hours"] = properties.AfterProperties["Mon_x0020_Hours"];
               item["User_x0020_ID_x0020_Plus_x0020_D"] = properties.AfterProperties["Monday_x0020_Username_x0020_Plus_x0020_Date"]; //row id
               item.Update();

               // add Tuesday
               SPListItem item2 = listItems.Add();
               item2["LinkTitle"] = strUsername; //username
               item2["First_x0020_Name"] = properties.AfterProperties["First_x0020_Name"];
               item2["Last_x0020_Name"] = properties.AfterProperties["Last_x0020_Name"];
               item2["Date"] = properties.AfterProperties["Tuesday_x0020_Date"];
               item2["Month"] = properties.AfterProperties["Tuesday_x0020_Month"];
               item2["Year"] = properties.AfterProperties["Year"];
               item2["Hours"] = properties.AfterProperties["Tues_x0020_Hours"];
               item2["User_x0020_ID_x0020_Plus_x0020_D"] = properties.AfterProperties["Tuesday_x0020_Username_x0020_Plus_x0020_Date"]; //row id
               item2.Update();

               // add Wednesday
               SPListItem item3 = listItems.Add();
               item3["LinkTitle"] = strUsername; //username
               item3["First_x0020_Name"] = properties.AfterProperties["First_x0020_Name"];
               item3["Last_x0020_Name"] = properties.AfterProperties["Last_x0020_Name"];
               item3["Date"] = properties.AfterProperties["Wednesday_x0020_Date"];
               item3["Month"] = properties.AfterProperties["Wednesday_x0020_Month"];
               item3["Year"] = properties.AfterProperties["Year"];
               item3["Hours"] = properties.AfterProperties["Wed_x0020_Hours"];
               item3["User_x0020_ID_x0020_Plus_x0020_D"] = properties.AfterProperties["Wednesday_x0020_Username_x0020_Plus_x0020_Date"]; //row id
               item3.Update();

               // add Thursday
               SPListItem item4 = listItems.Add();
               item4["LinkTitle"] = strUsername; //username
               item4["First_x0020_Name"] = properties.AfterProperties["First_x0020_Name"];
               item4["Last_x0020_Name"] = properties.AfterProperties["Last_x0020_Name"];
               item4["Date"] = properties.AfterProperties["Thursday_x0020_Date"];
               item4["Month"] = properties.AfterProperties["Thursday_x0020_Month"];
               item4["Year"] = properties.AfterProperties["Year"];
               item4["Hours"] = properties.AfterProperties["Thurs_x0020_Hours"];
               item4["User_x0020_ID_x0020_Plus_x0020_D"] = properties.AfterProperties["Thursday_x0020_Username_x0020_Plus_x0020_Date"]; //row id
               item4.Update();

               // add Friday
               SPListItem item5 = listItems.Add();
               item5["LinkTitle"] = strUsername; //username
               item5["First_x0020_Name"] = properties.AfterProperties["First_x0020_Name"];
               item5["Last_x0020_Name"] = properties.AfterProperties["Last_x0020_Name"];
               item5["Date"] = properties.AfterProperties["Friday_x0020_Date"];
               item5["Month"] = properties.AfterProperties["Friday_x0020_Month"];
               item5["Year"] = properties.AfterProperties["Year"];
               item5["Hours"] = properties.AfterProperties["Fri_x0020_Hours"];
               item5["User_x0020_ID_x0020_Plus_x0020_D"] = properties.AfterProperties["Friday_x0020_Username_x0020_Plus_x0020_Date"]; //row id
               item5.Update();

               // add Saturday
               SPListItem item6 = listItems.Add();
               item6["LinkTitle"] = strUsername; //username
               item6["First_x0020_Name"] = properties.AfterProperties["First_x0020_Name"];
               item6["Last_x0020_Name"] = properties.AfterProperties["Last_x0020_Name"];
               item6["Date"] = properties.AfterProperties["Saturday_x0020_Date"];
               item6["Month"] = properties.AfterProperties["Saturday_x0020_Month"];
               item6["Year"] = properties.AfterProperties["Year"];
               item6["Hours"] = properties.AfterProperties["Sat_x0020_Hours"];
               item6["User_x0020_ID_x0020_Plus_x0020_D"] = properties.AfterProperties["Saturday_x0020_Username_x0020_Plus_x0020_Date"]; //row id
               item6.Update();

               // add Sunday
               SPListItem item7 = listItems.Add();
               item7["LinkTitle"] = strUsername; //username
               item7["First_x0020_Name"] = properties.AfterProperties["First_x0020_Name"];
               item7["Last_x0020_Name"] = properties.AfterProperties["Last_x0020_Name"];
               item7["Date"] = properties.AfterProperties["Sunday_x0020_Date"];
               item7["Month"] = properties.AfterProperties["Sunday_x0020_Month"];
               item7["Year"] = properties.AfterProperties["Year"];
               item7["Hours"] = properties.AfterProperties["Sun_x0020_Hours"];
               item7["User_x0020_ID_x0020_Plus_x0020_D"] = properties.AfterProperties["Sunday_x0020_Username_x0020_Plus_x0020_Date"]; //row id
               item7.Update();
               #endregion

                          }
       }
   }

   /// <summary>
   /// An item is being updated.
   /// </summary>
   public override void ItemUpdating(SPItemEventProperties properties)
   {
       base.ItemUpdating(properties);

       // omitted this code since it works
   }

   /// <summary>
   /// An item is being deleted.
   /// </summary>
   public override void ItemDeleting(SPItemEventProperties properties)
   {
       base.ItemDeleting(properties);

       //omitted this code since it works
   }
}
share|improve this question
    
Is it defined as synchronous event? –  Ashish Patel May 17 '12 at 22:10
    
It's very hard to troubleshoot without see at least your Elements.xml –  Per Jakobsen May 18 '12 at 7:22
    
@LCountee please add code or we will have to close Q –  Anders Rask May 18 '12 at 8:31
    
@PerJakobsen Added code. –  LCountee May 18 '12 at 12:19
    
@AshishPatel Yes, it is synchronous. –  LCountee May 18 '12 at 12:49
show 1 more comment

2 Answers

up vote 0 down vote accepted

Please review this http://www.synergyonline.com/Blog/Lists/Posts/Post.aspx?ID=122, and I would suggest running your code in the ItemAdded Event Handler instead.

Frankly it should hit the break if you are debugging, but perhaps you can just avoid the issue all together.

share|improve this answer
    
Thanks for the link. I added an ItemAdded event handler, but it does not seem to be firing either (break point is not hit). –  LCountee May 18 '12 at 19:37
1  
Hrm.. at this point i would check (for the record) that when you select 'Event Receiver 1' or whatever your receiver is called in the Solution explorer, Handle ItemAdded/ItemAdding events are true, then if so i would try removing everything from the ItemAdding and ItemAdded events other than the base call and a break point, and if that doesn't go off, create a new project just for the ItemAdding event and see if you can get that to run. If NONE of those things gives you a result, call MS and get support :( –  Zork May 18 '12 at 20:09
    
I created a separate ItemAdded project, and was able to hit the break point I set within it. I don't know why the old one won't work, but at least this new one does. –  LCountee May 18 '12 at 21:46
add comment

Please check that event receiver is attached or not, using following codeplex tool. http://speventreceiverman.codeplex.com/

share|improve this answer
    
Thanks for suggesting that tool. I ran it, and the three event handlers I've implemented all appear in red, so I guess that means they are attached? If not, how can I check whether they are attached? –  LCountee May 18 '12 at 12:53
    
Other way is log some activity in text file,ULS log or Application log for testing that receiver is getting called. Once done make sure to remove this logging functionality. –  Prasad Pathak May 18 '12 at 13:02
    
SharePoint Manager 2010 will show you exactly what is and is not attached to a list or library –  Zork May 18 '12 at 14:16
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.