Share via


Add Method

The Add method of the SPListItemCollection class creates an item but requires the Update method to actually add the item to the list.

Return Value

A Microsoft.SharePoint.SPListItem object that represents the new item.

Remarks

To add an item to a list, call the Add method and assign its return value to an SPListItem object. Use indexers on this object for each field to assign specific values, and then call the Update method on the item to effect changes in the database.

Use list.RootFolder.Files.Add to add files to a document library, where list is an SPList object.

This method returns a System.Exception exception if applied to a document library.

Example

The following code example adds a new item to a specified list.

This example requires using directives (Imports in Visual Basic) for both the Microsoft.SharePoint and Microsoft.SharePoint.WebControls namespaces.

Requirements

Platforms: Microsoft Windows Server 2003

Security: Code Access Security