1 06 2011
Reordering Content Types Programmatically
After this question was asked on SharePoint Stack Exchange, I thought I’d share my method of re-ordering content types in a list.
Note: this isn’t the only method of doing this, see the thread on SPSE to see more (particularly the UniqueContentTypeOrder property).
1 |
private void ReorderContentTypes(SPWeb web, string listName, string firstContentTypeName)<br>{<br> SPList list = web.Lists[listName];<br><br> SPContentType cType = web.AvailableContentTypes[firstContentTypeName];<br><br> List<SPContentType> oldCTypes = new List<SPContentType>();<br><br> for (int i = list.ContentTypes.Count -1; i >= 0; i--)<br> {<br> if (!list.ContentTypes[i].Id.IsChildOf(cType.Id))<br> {<br> oldCTypes.Add(list.ContentTypes[i]);<br><br> list.ContentTypes[i].Delete();<br> }<br> }<br><br> foreach (SPContentType c in oldCTypes)<br> {<br> list.ContentTypes.Add(c);<br> }<br><br> list.Update();<br>}<br> |
SPList.Items versus the SPQuery List Item Performance – Updating Large Lists