Partilhar via


SPListCollection.Add Method (String, String, SPListTemplate)

Creates a list with the specified title, description, and list template object.

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

Syntax

'Declaration
Public Overridable Function Add ( _
    title As String, _
    description As String, _
    template As SPListTemplate _
) As Guid
'Usage
Dim instance As SPListCollection
Dim title As String
Dim description As String
Dim template As SPListTemplate
Dim returnValue As Guid

returnValue = instance.Add(title, description, _
    template)
public virtual Guid Add(
    string title,
    string description,
    SPListTemplate template
)

Parameters

  • description
    Type: System.String

    A string that contains the description.

Return Value

Type: System.Guid
A GUID that identifies the new list.

Examples

The following code example creates a list in each of the sites of a site collection. The list is based on the template for a Contacts list.

Dim oSiteCollection As SPSite =  SPContext.Current.Site 
Dim collWebsites As SPWebCollection = oSiteCollection.AllWebs
For Each oWebsiteAs SPWeb In collWebsites
    Dim collList As SPListCollection =  oWebsite.Lists 
    collList.Add("New_List_Name", "List_Description", SPListTemplateType.Contacts)
    oWebsite.Dispose()
Next
SPSite oSiteCollection = SPContext.Current.Site;
SPWebCollection collWebsites = oSiteCollection.AllWebs
foreach (SPWeb oWebsite in collWebsites)
{
    SPListCollection collList = oWebsite.Lists;
    collList.Add("New_List_Name", "List_Description", SPListTemplateType.Contacts);
    oWebsite.Dispose();
}

Note

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.

See Also

Reference

SPListCollection Class

SPListCollection Members

Add Overload

Microsoft.SharePoint Namespace