SPListCollection.Add method (String, String, SPListTemplate)
SharePoint 2013
Creates a list with the specified title, description, and list template object.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
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.
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
|
|---|
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. |
Note