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.


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\""


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.

Get Available PowerShell Commands for SharePoint on Client-Side

Needless to say, that on Client Side, we get a limited scope of running various SharePoint commands. As a result there aren’t much cmdlets for the Client Side. So how do you know what are the available commands that might come handy while executing cmdlets remotely? Simply run the following command in PowerShell or SharePoint Online Management Shell.
get-command | Where-Object { $_.ModuleName -eq "Microsoft.Online.SharePoint.PowerShell" }

A sample list of available cmdlets are displayed in the following screenShot.