ListCollection.Add Method
Creates a new list or a document library.
Namespace: Microsoft.SharePoint.Client
Assemblies: Microsoft.SharePoint.Client.Silverlight (in Microsoft.SharePoint.Client.Silverlight.dll); Microsoft.SharePoint.Client (in Microsoft.SharePoint.Client.dll)
Syntax
'Declaration
<RemoteAttribute> _
Public Function Add ( _
parameters As ListCreationInformation _
) As List
'Usage
Dim instance As ListCollection
Dim parameters As ListCreationInformation
Dim returnValue As List
returnValue = instance.Add(parameters)
[RemoteAttribute]
public List Add(
ListCreationInformation parameters
)
Parameters
parameters
Type: Microsoft.SharePoint.Client.ListCreationInformationA ListCreationInformation object that represents information associated with the list or document library.
It must not be a null reference (Nothing in Visual Basic).
Return Value
Type: Microsoft.SharePoint.Client.List
Returns a List instance representing the creation of list or a document library.
Exceptions
Exception | Condition |
---|---|
MetadataObjectNotFoundException | ListCreationInformation.Url is not valid. |
[Microsoft.BusinessData.MetadataModel.MetadataObjectNotFoundException] | Entity specified in ListCreationInformation.DataSourceProperties or the specified SpecificFinder does not exist on the server. Error code: -1. |
[Microsoft.SharePoint.SPException] | Entity specified in ListCreationInformation.DataSourceProperties does not have a View with the specified SpecificFinder. Error code: -2146232832. |
SPException | The location for list does not exist, the current user has insufficient permissions to perform the operation, ListCreationInformation.Title is a null reference (Nothing in Visual Basic), ListCreationInformation.Url is not valid, or another list with the title already exists in the site. Error code: -2130575342. |
[Microsoft.SharePoint.SPException] | List server template is not valid. Error code: -2130575237. |
[Microsoft.SharePoint.SPException] | Feature does not exist. Error code: -2130246262. |
UnauthorizedAccessException | The list server template is not valid. The current user has insufficient permissions. Error code: -2147024891. |
Examples
This code example creates two new announcements lists and adds them to the list collection of the current web site.
using System;
using Microsoft.SharePoint.Client;
namespace Microsoft.SDK.SharePointFoundation.Samples
{
class ListCollection_AddExample
{
static void Main()
{
string siteUrl = "http://MyServer/sites/MySiteCollection";
ClientContext clientContext = new ClientContext(siteUrl);
Web site = clientContext.Web;
ListCollection collList = site.Lists;
ListCreationInformation lci1 = new ListCreationInformation();
lci1.Title = "New Announcements";
lci1.TemplateType = (int)ListTemplateType.Announcements;
site.Lists.Add(lci1);
ListCreationInformation lci2 = new ListCreationInformation();
lci2.Title = "Old Announcements";
lci2.TemplateType = (int)ListTemplateType.Announcements;
site.Lists.Add(lci2);
clientContext.Load(collList);
clientContext.ExecuteQuery();
Console.WriteLine("Lists on the current site:\n\n");
foreach (List targetList in collList)
Console.WriteLine(targetList.Title);
}
}
}