Skip to main content
Tweeted twitter.com/StackSharePoint/status/707109570053808129
edited body
Source Link
Robert Lindgren
  • 24.5k
  • 12
  • 53
  • 79

I am not able to create a list content type using the below snippet. It throws a ServerException with additional information - "The site content type has already been added to this list.":

The site content type has already been added to this list.

   var list =  clientContext.Web.Lists.GetByTitle("sometitle");
   var documentCT = clientContext.Web.ContentTypes.GetById("0x0101");
   clientContext.Load(list,l=> l.ContentTypes);
   clientContext.Load(documentCT);
   clientContext.ExecuteQuery();

   var test = new ContentTypeCreationInformation(){
        Name = "TestCT", ParentContentType =documentCT };

   list.ContentTypes.Add(test);

   list.Update();
   clientContext.ExecuteQuery();

Basically, I want to create a list content type whose parent is the "Document" CT.

I am not able to create a list content type using the below snippet. It throws a ServerException with additional information - "The site content type has already been added to this list."

   var list =  clientContext.Web.Lists.GetByTitle("sometitle");
   var documentCT = clientContext.Web.ContentTypes.GetById("0x0101");
   clientContext.Load(list,l=> l.ContentTypes);
   clientContext.Load(documentCT);
   clientContext.ExecuteQuery();

   var test = new ContentTypeCreationInformation(){
        Name = "TestCT", ParentContentType =documentCT };

   list.ContentTypes.Add(test);

   list.Update();
   clientContext.ExecuteQuery();

Basically, I want to create a list content type whose parent is the "Document" CT.

I am not able to create a list content type using the below snippet. It throws a ServerException with additional information :

The site content type has already been added to this list.

   var list =  clientContext.Web.Lists.GetByTitle("sometitle");
   var documentCT = clientContext.Web.ContentTypes.GetById("0x0101");
   clientContext.Load(list,l=> l.ContentTypes);
   clientContext.Load(documentCT);
   clientContext.ExecuteQuery();

   var test = new ContentTypeCreationInformation(){
        Name = "TestCT", ParentContentType =documentCT };

   list.ContentTypes.Add(test);

   list.Update();
   clientContext.ExecuteQuery();

Basically, I want to create a list content type whose parent is the "Document" CT.

Source Link

Creating list content type using csom

I am not able to create a list content type using the below snippet. It throws a ServerException with additional information - "The site content type has already been added to this list."

   var list =  clientContext.Web.Lists.GetByTitle("sometitle");
   var documentCT = clientContext.Web.ContentTypes.GetById("0x0101");
   clientContext.Load(list,l=> l.ContentTypes);
   clientContext.Load(documentCT);
   clientContext.ExecuteQuery();

   var test = new ContentTypeCreationInformation(){
        Name = "TestCT", ParentContentType =documentCT };

   list.ContentTypes.Add(test);

   list.Update();
   clientContext.ExecuteQuery();

Basically, I want to create a list content type whose parent is the "Document" CT.