Programmatically Create Content Types

This is an example of programmatically creating a content type (based on the Document content type) and adding it to a list. I’ve not added any extra columns or anything – but we could have.

string name = ...
SPList list = ...
SPContentType baseContentType = web.ContentTypes[SPBuiltInContentTypeId.Document];
SPContentType type = new SPContentType(baseContentType,web.ContentTypes,name);
list.ContentTypes.Add(type);
list.Update();

Advertisements
Programmatically Create Content Types

One thought on “Programmatically Create Content Types

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s