SPList.Items.Add() v/s SPList.AddItem()

The result of both the methods are same. They both add a new SPListItem to a SharePoint List (SPList) and returns back the newly created item. The difference lies in the process of creating the new items. SPList.Items.Add() explicitly adds a new item to the SharePoint List whereas SPList.AddItem() adds it implicitly.

In order to add a new item, it is required to get the current Lists schema. It is done by calling GetItems. This call takes place internally, so we don’t have any control over it. However, this is where the said two functions differs as they both execute different queries to get their respective ListItems.

SPList.Items.Add()

In the first case,

var newItem = list.Items.Add();

ListItemCollection is initialized using the following query before creating a new item:

new SPQuery()
{
    ViewAttributes = "Scope=\"Recursive\""
});

SPList.AddItem() 

In this case,

var newItem = list.AddItem();

ListItemCollection is initialized using the following query:

new SPQuery()
{
    Query = "-1",
    ViewFields = ""
};

We can clearly see that this is a fake query as it is querying for a ListItem whose ID is -1! It means that the ListItemCollection will always be zero while adding a new item.


This difference gets reflected in the execution time for these queries. Expectedly, the second query, SPList.AddItem(), is much more faster especially while dealing with a List with large number of items.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.