Freigeben über


ListCollection.Add-Methode

Erstellt eine neue Liste oder eine Dokumentbibliothek.

Namespace:  Microsoft.SharePoint.Client
Assemblys:   Microsoft.SharePoint.Client.Silverlight (in Microsoft.SharePoint.Client.Silverlight.dll);  Microsoft.SharePoint.Client.Phone (in Microsoft.SharePoint.Client.Phone.dll)  Microsoft.SharePoint.Client (in Microsoft.SharePoint.Client.dll)

Syntax

'Declaration
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)
public List Add(
    ListCreationInformation parameters
)

Parameter

Rückgabewert

Typ: Microsoft.SharePoint.Client.List
Gibt eine List -Instanz, die die Erstellung einer Liste oder einer Dokumentbibliothek darstellt.

Ausnahmen

Ausnahme Bedingung
MetadataObjectNotFoundException

ListCreationInformation.Url ist ungültig.

[Microsoft.BusinessData.MetadataModel.MetadataObjectNotFoundException]

Auf dem Server vorhanden nicht in ListCreationInformation.DataSourceProperties oder die angegebenen SpecificFinder angegebene Entität. Fehlercode:-1.

[Microsoft.SharePoint.SPException]

Eine Ansicht mit der angegebenen SpecificFinder keinen Entität in ListCreationInformation.DataSourceProperties angegeben. Fehlercode:-2146232832.

SPException

Der Speicherort für die Liste ist nicht vorhanden, der aktuelle Benutzer ist nicht berechtigt, die zum Ausführen des Vorgangs, ListCreationInformation.Title ist ein Nullverweis (Nothing in Visual Basic), ListCreationInformation.Url ist ungültig oder einer anderen Liste mit dem Titel der Website bereits vorhanden ist. Fehlercode:-2130575342.

[Microsoft.SharePoint.SPException]

Server-Listenvorlage ist ungültig. Fehlercode:-2130575237.

[Microsoft.SharePoint.SPException]

Features ist nicht vorhanden. Fehlercode:-2130246262.

UnauthorizedAccessException

Die Listenvorlage-Server ist ungültig.

Der aktuelle Benutzer verfügt nicht über ausreichende Berechtigungen. Fehlercode:-2147024891.

Beispiele

In diesem Codebeispiel erstellt zwei neue Ankündigungslisten und der Liste-Auflistung des der aktuellen Website hinzugefügt.

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

        }
    }
}

Siehe auch

Referenz

ListCollection Klasse

ListCollection-Member

Microsoft.SharePoint.Client-Namespace