Posted by: R Manimaran | October 12, 2010

Programmatically set the New button order for a Document Library

Change new button order and default content type


Programmatically set the New button order for a Document Library

Suppose you have a document Library contains the following content Types.

· Project Folder

· Sub Project Folder

· Document


Project Folder derived from Folder content type.

Sub Project Folder derived from Project Folder

Below that you have allow the user to Creates a document.

But if three content types are attached to document library, then in New Button it will come like this.

Here we have another ‘new’ option ‘Folder’. To remove follow this.

Settings àDocument Library Settings àAdvanced Settings

Set ‘No’ to Display “New Folder” command on the New menu? option.

Now the menu will look like this

But our requirement

§ If you are in the Root level only Project Folder needs to come.

§ If you are inside the Project Folder only Sub Project Folder menu has to come.

§ If you are inside the Sub Project folder then only document menu has to come.

Something like this.

Check my previous post here to set this default content type.

How to set programmatically

Here for the Document Library root folder we set Project Folder as default

SPList myList = Web.Lists[“MyProjects”];

if (myList != null)


//Remove the ‘Folder’ menu item from the New Menu option

myList.EnableFolderCreation = false;


SPContentTypeCollection oContentTypes = myList.ContentTypes;

SPFolder rootFolder = myList.RootFolder;

SPContentType[] orderedContentTypes = new SPContentType[1];

foreach (SPContentType oContentType in oContentTypes)


if (oContentType.Name == “Project Folder“)


orderedContentTypes[0] = oContentType;

rootFolder.UniqueContentTypeOrder = orderedContentTypes;






Now create an Item Event Receiver. In the ItemAdded event check the current content type of the added item. Based on that, assign next level new menu option, to the created folder.



  1. thanks a lot , it is very helpfull for me

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: