0

Has anyone been able to re-order content types for a list in code?

If I'm given a specific content type, I want to make it the default in a list, by re-ordering the SPList.ContentTypes collection and setting my content type to position 0.

I've tried making a new collection (SPContentTypeCollection), setting the order in a loop and replacing the SPList.ContentTypes, but unfortunately that property is read-only.

The SPBaseCollection (which is inherited by SPContentTypeCollection) is pretty darned limited when it comes to collection operations.

1

It's been a while since I had to do this. But from memory, rather than playing with the SPContentTypeCollection on the SPList, you should modify the SPFolder.UniqueContentTypeOrder property on the SPList.RootFolder.

Doing this will let you re-order the ContentTypes, and from memory you are correct about the item at index 0 being the Default.

2
  • Awesome, cheers! The UniqueContentTypeOrder is an IList which is nicer to play with. Why do all things with content types have so many aliases? :(
    – James Love
    Jan 14 '11 at 12:51
  • how can we do that with rest api ? Dec 10 '19 at 13:09

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.