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
}
}