Partager via


ContentTypeCollection.Add - Méthode

Adds a new content type to the collection.

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 ContentTypeCreationInformation _
) As ContentType
'Utilisation
Dim instance As ContentTypeCollection
Dim parameters As ContentTypeCreationInformation
Dim returnValue As ContentType

returnValue = instance.Add(parameters)
public ContentType Add(
    ContentTypeCreationInformation parameters
)

Paramètres

  • parameters
    Type : Microsoft.SharePoint.Client.ContentTypeCreationInformation

    A ContentTypeCreationInformation object that represents information associated with the content type. It specifies properties that will be used to construct the new content type. It must not be une référence Null (Rien dans Visual Basic). The content type scope of its ParentContentType property must not be an ancestor of the parent of the content type collection. The ParentContentType property specifies the parent content type for the content type that will be constructed.

Valeur renvoyée

Type : Microsoft.SharePoint.Client.ContentType
A new ContentType object to add to the collection.

Exceptions

Exception Condition
[ServerException]

The collection is read only.

[SPException]

A content type with a name specified by the Name property of parameters exists in the collection. Error code: 183.

Exemples

This code example initializes a custom content type, adds it to the collection of content types, and displays the names of the specified website’s content types.

using System;
using Microsoft.SharePoint.Client;

namespace Microsoft.SDK.SharePointFoundation.Samples
{
    class ContentTypeCollectionAddExample
    {
        static void Main()
        {

            string siteUrl = "http://MyServer/sites/MySiteCollection";

            ClientContext clientContext = new ClientContext(siteUrl);
            Web site = clientContext.Web;
            ContentTypeCollection collContentType = site.ContentTypes;

            // Initialize a new content type.
            ContentTypeCreationInformation contentInfo = new ContentTypeCreationInformation();
            contentInfo.Name = "myContentType";
            contentInfo.Description = "My custom content type";
            ContentType contentType = collContentType.Add(contentInfo);

            clientContext.Load(collContentType);
            clientContext.ExecuteQuery();

            foreach (ContentType myType in collContentType)
                Console.WriteLine("Content Type Name: {0}", myType.Name);
        }

    }
}

Voir aussi

Référence

ContentTypeCollection classe

ContentTypeCollection - Membres

Microsoft.SharePoint.Client - Espace de noms