This topic has not yet been rated - Rate this topic

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)
public virtual Guid Add(
	string title,
	string description,
	SPListTemplate template
)

Parameters

title
Type: System.String
A string that contains the title.
description
Type: System.String
A string that contains the description.
template
Type: Microsoft.SharePoint.SPListTemplate
An SPListTemplate object that represents the list definition or list template.

Return value

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

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.

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 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.

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.