private void ChangeOrHideContentTypesInALibrary(SPList list) { list.ContentTypesEnabled = true; SPFolder folder = list.RootFolder; List<SPContentType> orderedContentTypes = new List<SPContentType>(); foreach (SPContentType ct in folder.ContentTypeOrder) { if (ct.Name.Contains("ContentType1") || ct.Name.Contains("ContentType2")) orderedContentTypes.Add(ct); } folder.UniqueContentTypeOrder = orderedContentTypes; folder.Update(); }
If you observe the above code, then the variable orderedContentTypes is what having the content types of which we need to show in the NEW button of the list toolbar. In which order we add the content types to this variable, that order they will be added to the list and shown on the toolbar. And second thing is out of 3 content types available in the above logic we have added only two to the variable. So the third content type will be hidden from the toolbar. And the last two lines in the above function are to update the list with the latest content types order.
Hope this gives you clear idea on how to order and hide content types on a list/library.
Loved this option.. Great work..
ReplyDeleteNik