Tuesday, May 01, 2012

More performant way to add items to SharePoint List

SPList.Items.Add(); -this code actually attempts to retrieve all items of the list.

Actually, you may retrieve an empty SPListItemCollection without querying the database by calling SPList.GetItems() and passing an SPQuery object designed to return no rows. So to add an item to a SharePoint list, use the following code instead: SPListItem newItem = SPList.GetItems(new SPQuery(){Query = "0"}).Add();

Mann, Steven; Murphy, Colin; Gazmuri, Pablo; Wheeler, Christina; Caravajal, Chris (2012-01-31). SharePoint 2010 Field Guide (Kindle Locations 8516-8520). John Wiley and Sons. Kindle Edition.