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 Answer 1

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()
1
  • Thanks, worked it out shortly after. Cheers for posting. Nov 3, 2017 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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