1

Hi I am creating my own content types and assigning them to my new lists like so

var contentType = clientContext.Web.ContentTypes.GetById(ContentTypeID);
list.ContentTypesEnabled = true;
list.ContentTypes.AddExistingContentType(contentType);

This works well, however, I do not need to have the default content type attached to these lists. See below.

The Default Content Type

How can I remove it via code?

Researching more into it, I now know there is a variable called UniqueContentTypeOrder and I try to apply the new content type ID I want on to it. For example.

IList<ContentTypeId> ctoFolder = new List<ContentTypeId>();

ctoFolder.Add(contentType.Id);

list.RootFolder.UniqueContentTypeOrder = ctoFolder;
list.RootFolder.Update();
list.Update();
clientContext.ExecuteQuery();

However, when executing the query I am getting an "Unknown error" in the catch

Any ideas?

Thanks

1

Use ContentTypeCollection.GetById method to get the specific content type and then delete it from the list.

$contentTypeID="<content type id>"
#Delete the content type from the list
list.ContentTypes.GetById($contentTypeID).DeleteObject()
  • Thanks, worked it out shortly after. Cheers for posting. – user3428422 Nov 3 '17 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.