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

Or

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

Here

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;

myList.Update();

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;

rootFolder.Update();

break;

}

}

}

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.

About these ads

Responses

  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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.

Join 26 other followers

%d bloggers like this: