This documentation is archived and is not being maintained.

SPContentType Constructor

Windows SharePoint Services 3

Initializes a new instance of the SPContentType class.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public SPContentType(
	SPContentType parentContentType,
	SPContentTypeCollection collection,
	string name


Type: Microsoft.SharePoint.SPContentType
An SPContentType object from which this content type will be derived.
Type: Microsoft.SharePoint.SPContentTypeCollection
An SPContentTypeCollection object that represents the collection to which this content type will be added.
Type: System.String
A String object that contains the name of the content type. This string is set as the value of the new content type Name property.

The collection object that you pass as the second argument to the constructor is used to obtain certain initial values for properties of the new content type. However, the new content type is not automatically added to the collection. You must do that yourself in a subsequent call to the Add(SPContentType) method.

The following example creates a content type that is derived from the “Item” type and then adds the new type to the site collection.

SPSite site = new SPSite("http://localhost");
SPWeb web = site.OpenWeb();

// Get a reference to the site content type collection.
SPContentTypeCollection contentTypes = web.ContentTypes;

// Create a Customer content type derived from the Item content type.
SPContentType contentType = new SPContentType(contentTypes["Item"], contentTypes, "Customer");

// Add the content type to the site collection.
contentType = contentTypes.Add(contentType);

// Clean up.