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();
Hello!
Nice brief post. I have the similar post in my blog – http://dotnetfollower.com/wordpress/2011/09/sharepoint-how-to-add-content-type-programmatically/. I show also how to add fields to the new content type and how to set required id of the content type – http://dotnetfollower.com/wordpress/2011/09/sharepoint-how-to-set-id-for-just-created-spcontenttype/.
Thanks!