Enabling content type management for SPList fails
-
08-10-2020 - |
Pergunta
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.
- The list is created correctly.
- 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.
- The same behaviour was on several lists.
What do I do wrong?
Solução
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"]);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange