Compartilhar via


SPList.AddItem Method (String, SPFileSystemObjectType)

Creates a list item of a specified type in the specified folder in the list.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public Function AddItem ( _
    folderUrl As String, _
    underlyingObjectType As SPFileSystemObjectType _
) As SPListItem
'Usage
Dim instance As SPList
Dim folderUrl As String
Dim underlyingObjectType As SPFileSystemObjectType
Dim returnValue As SPListItem

returnValue = instance.AddItem(folderUrl, _
    underlyingObjectType)
public SPListItem AddItem(
    string folderUrl,
    SPFileSystemObjectType underlyingObjectType
)

Parameters

  • folderUrl
    Type: System.String

    The server-relative URL of the folder where the list item should be created. The URL should begin with a forward slash; for example, /sites/mysite/subweb/Lists/mylist/myfolder.

  • underlyingObjectType
    Type: Microsoft.SharePoint.SPFileSystemObjectType

    One of the enumeration values that specifies the type of file system object that the new list item represents. The only valid types are File and Folder. If you pass another value, an exception is thrown when you call the Update method on the SPListItem object.

Return Value

Type: Microsoft.SharePoint.SPListItem
The new item.

Remarks

This method calls the AddItem(String, SPFileSystemObjectType, String) method with folderUrl, underlyingObjectType, and null .

To add an item to a list, first call the AddItem method to create a list item of the specified type in the specified folder with an automatically generated name. Then use indexers on the returned SPListItem object to assign specific values for each field of the item. Finally, call the Update method to commit the changes to the database.

Important

The new item is not added to the list until you save it to the content database by calling the SPListItem.Update method.

See Also

Reference

SPList Class

SPList Members

AddItem Overload

Microsoft.SharePoint Namespace

Add(String, SPFileSystemObjectType)

FileSystemObjectType

Url