I am trying to update current items, but all items in the list get updated why?
public override void ItemAdding(SPItemEventProperties properties)
{
using (SPWeb web = properties.OpenWeb())
{
SPList myList = web.Lists.TryGetList("DocumentList");
SPListItemCollection itemCollection = myList.Items;
web.AllowUnsafeUpdates = true;
for (int iCount = 0; iCount < itemCollection.Count; iCount++)
{
SPListItem _item = itemCollection[iCount];
_item["MyField"] = "";
_item.Update();
}
}}
properties.ListItem
instead, because that is the one that is being added. Don't loop over all items.