SPListCollection.Add method (String, String, SPListTemplateType)

Creates a list with the specified title, description, and list definition type.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public virtual Guid Add(
	string title,
	string description,
	SPListTemplateType templateType
)

Parameters

title
Type: System.String

A string that contains the title.

description
Type: System.String

A string that contains the description.

templateType
Type: Microsoft.SharePoint.SPListTemplateType

An enumeration value that specifies the type of list definition.

Return value

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

This overload of the Add method applies only to the default Microsoft SharePoint Foundation list templates that are represented by the Microsoft.SharePoint.SPListTemplateType enumeration. To create lists based on other list templates, use one of the other Add method overloads.

The following code example creates a Contacts list in every site within the current site collection.

SPSite oSiteCollection = SPContext.Current.Site;
using(SPWebCollection collWebsites = oSiteCollection.AllWebs)
{
    foreach (SPWeb oWebsite in collWebsites)
    {
        SPListCollection collList = oWebsite.Lists;
        collList.Add("New_List_Name", "List_Description",
            SPListTemplateType.Contacts);
    }
}
NoteNote

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.

Show: