Tuesday, February 17, 2009

Enable managing content types by default at list creation

When we create a list/ document library , Manage Content Type is disabled by default. If you are creating a list using Feature , you have two choices to enable it. Also you can enable Versioning and Minor versions the same way.

1. In the List instance CAML
2. Using Feature receiver

Code ( CAML ):

<List FeatureId="FeatureGUIDOfTheListDefinition" Type="101" Title="DocumentLibWithContentTypeEnabled"  EnableContentTypes ="TRUE " Description ="This list instance of Document Library will have content type enabled by default" EnableMinorVersions ="TRUE " VersioningEnabled ="TRUE " Url="DocumentLibWithContentTypeEnabled" />
Code ( Feature Receiver ):
 public void OnActivated(SPFeatureReceiverProperties properties)
SPWeb web = properties.Feature.Parent as SPWeb;
SPList list = web.Lists["NameOfTheList"];
list.ContentTypesEnabled = true;
list.EnableVersioning = true;
list.EnableMinorVersions = true;