Question

I have the following code:

oWeb.Update(); 
oWeb.Lists.Add("SampleList", "Some description", SPListTemplateType.GenericList); 
oWeb.Update(); 
oWeb.Lists["SampleList"].ContentTypesEnabled = true; 
oWeb.Lists["SampleList"].EnableVersioning = true; 
oWeb.Lists["SampleList"].Update(); 
SPContentType SomeCT = oWeb.AvailableContentTypes[SomeCTName]; 
oWeb.Lists["SampleList"].ContentTypes.Add(SomeCT); 
oWeb.Lists["SampleList"].ContentTypes["Item"].Delete(); 
oWeb.Lists["SampleList"].Update(); 
oWeb.Update();

Neither versioning nor Content type Management are enabled.

  1. The list is created correctly.
  2. When I go to User Interface>List Settings>Advanced>Content Type Management>Yes>Save, then the CT are enabled and the SomeCT content type I am adding in the lines below is visible.
  3. The same behaviour was on several lists.

What do I do wrong?

Was it helpful?

Solution

Try this

SPListCollection lc = oWeb.Lists;
lc.Add("SampleList", "", SPListTemplateType.GenericList);
SPList l = oWeb.Lists["SampleList"];
l.EnableVersioning = true;
l.ContentTypesEnabled = true;
l.Update();
l.ContentTypes.Add(oSiteCollection.RootWeb.ContentTypes["SomeCT"]);
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top