Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a problem which concerns hiding content types in the "Add new item"-Ribbon-Button.

In Visual Studio, I defined 2 custom content types (derived from the default folder content type) and a custom list (in that list I added the 2 custom content types). When I deploy the project, I can open the list in SharePoint and with the help of the "Add new item"-Ribbon-Button, I am able to create folder-items which are defined by the 2 custom content types mentioned before. When I create a folder-item, I can go "into" that folder and create another folder-item. So I get a list of nested folders (first-level-folders, second-level-folders, etc.).

But: within the first-level folder, I want to allow only the creation of folder-items defined by ONE of the two custom content types. That means on the "Add new item"-Ribbon-Button, only ONE custom type should appear.

I can do that manually by going into the context-menu of the titel of the first-level-folder, then I choose "Change Content Type Order" (if that is the right translation ... I have a German SharePoint, there it's called "Reihenfolge der neuen Schaltflächen ändern"), and there, by unchecking the respective checkbox, I am able to change the visibility ot the content types which are shown in the "Add new item"-Ribbon Button.

But how can I do that programmatically? I can't find any propierties in the XML of the content type definition. Isn't there any property which says: "By default, only allow the creation of a specific content type within a folder of THIS content type"? The problem is that in the first level of the list I will have about 900 entries, and I don't want to do the changes manually 900 times.

Mayby someone of you could point me to the right direction?

Thank you! Mike

share|improve this question
add comment

1 Answer

The property you want is SPFolder.UniqueContentTypeOrder.

Create an array of SPContentTypes that containt the CTypes you want in the order you want them. Then set the UniqueContentTypeOrder on the root folder of the list.

SPContentType[] newOrder = new SPContentType[] { ctype1, ctype2, etc };
SPFolder folder = list.RootFolder;
folder.UniqueContentTypeOrder = newOrder;
folder.Update();
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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