I have two contact lists in my site i.e. Contacts 1 and Contacts 2.
I am creating "item added" event receiver on Contacts 1 that is whenever new entry is made to the Contacts 1 automatically it should be dropped to the Contacts 2.
My logic for copying the entry to the Contacts 2 list is:
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
if (properties.List.Title.Equals("Contacts 1"))
{
using (SPSite site = new SPSite(properties.WebUrl))
{
SPWeb web = site.RootWeb;
SPList list = web.Lists["Contacts 2"];
SPListItem item = list.Items.Add();
foreach (SPField field in properties.List.Fields)
{
item[field.Title] = properties.ListItem[field.Title].ToString();
}
item.Update();
}
}
}
I am still not getting the item copied in the list 'Contacts 2'
What should I do to tackle this error.? Please help.