Partager via


ListCollection.Add - Méthode

Creates a new list or a document library.

Espace de noms :  Microsoft.SharePoint.Client
Assemblys :   Microsoft.SharePoint.Client.Silverlight (dans Microsoft.SharePoint.Client.Silverlight.dll);  Microsoft.SharePoint.Client.Phone (dans Microsoft.SharePoint.Client.Phone.dll)  Microsoft.SharePoint.Client (dans Microsoft.SharePoint.Client.dll)

Syntaxe

'Déclaration
Public Function Add ( _
    parameters As ListCreationInformation _
) As List
'Utilisation
Dim instance As ListCollection
Dim parameters As ListCreationInformation
Dim returnValue As List

returnValue = instance.Add(parameters)
public List Add(
    ListCreationInformation parameters
)

Paramètres

Valeur renvoyée

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 une référence Null (Rien dans 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.

Exemples

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);

        }
    }
}

Voir aussi

Référence

ListCollection classe

ListCollection - Membres

Microsoft.SharePoint.Client - Espace de noms