Click here to Skip to main content
15,501,012 members
Articles / Programming Languages / Javascript
Posted 18 Jan 2009


26 bookmarked

SharePoint Customization Tricks - Part 1

Rate me:
Please Sign up or sign in to vote.
4.00/5 (5 votes)
18 Jan 2009CPOL2 min read
Trick #1: Hiding the list view toolbar menu items!


This multipart series of articles is intended to help you get ramped up with SharePoint customizations. It's about modifying the default SharePoint user experience, list forms customization, branding, skinning SharePoint portals, etc. When I looked around the “SharePoint Landscape”, I noticed the lack of documented experiences in the SharePoint customization area, and thus this multipart series of articles was born.


First, you need to have skills in .NET development and in particular ASP.NET development. You should also have basic understanding of JavaScript, SharePoint, and how to use it from the User Interface, and of course, you should have some experience in using the SharePoint customization tool (SharePoint Designer).

Trick #1 : Hiding the List View Toolbar Menu Items!


I've gone through SharePoint projects on different scales; a common requirement among most of these projects is hiding some menu items that are implemented by default within the framework of SharePoint. The obvious choice from the SDK is HideCustomAction! After digging through the web, I found out the following:

  • The "HideCustomAction" feature can merely hide the items which have been rendered through the "CustomAction" framework features such as Site Actions and Site Setting etc.
  • ECB (Context Menu) items are rendered by JavaScript from the Core.js file so we can't hide them via the "HideCustomAction" feature. However, you can add a new menu item in the ECB menu through the "CustomAction" feature and hide it again through the "HideCustomAction" feature. In other words, the "HideCustomAction" feature can be used to hide the ECB menu items that you created via CustomAction, but can't be used to hide the out of the box menu items.
  • The ListViewWebPart menu items (New menu, Upload menu, Actions menu, … etc.) are rendered through a class library as a web control from the Microsoft.SharePoint.dll, so they can't be hidden through the "HideCustomAction" feature.

Hmm, I thought of delving back into the world of JavaScript, and I came up with some generic functions that can be used to hide any menu item in SharePoint, and I decided to share them with the community.

hideListViewToolbarItems("Edit in Datasheet", "export to Spreadsheet",
    "view rss feed","settings:create view");

function hideListViewToolbarItems()
	/// <summary>
	/// By : Ayman M. El-Hattab ( )
	/// </summary>
	var menuItem;	
	var menuItemName;
	var menuItemIndex=-1;
	var menuItemNames=new Array("edit in datasheet", 
	  "open with windows explorer",
	  "connect to outlook",'export to spreadsheet','view rss feed','alert me'
	  ,"create column","settings:create view","list settings",
	  "document library settings","explorer view","all documents",
	  "all items","modify this view", 
	  "view:create view","new document",
	  "new item","new folder","upload document", 
	  "upload multiple documents");
	var menuItems = new Array("EditInGridButton", 

	var allMenuItems = document.getElementsByTagName('ie:menuitem');
	for(var i = 0; i < hideListViewToolbarItems.arguments.length; i++ ) 
		menuItemName= hideListViewToolbarItems.arguments[i].toLowerCase();
		for (j=0; j < menuItemNames.length; j++) 
				menuItemIndex = j;

		for (var l = 0; l < allMenuItems.length; l++)
				menuItemName = menuItemName.split(":")[1];
			if (allMenuItems[l].id.indexOf(menuItem)!=-1 
		        && allMenuItems[l].text.toLowerCase() == menuItemName)
				// For FireFox Compatibility
				var parentNodeOfMenuItem = allMenuItems[l].parentNode;

You can use this function to hide any menu item rendered in the ListViewWebPart toolbar which is used in the list view pages. Just call the function and pass the menu item names (comma separated) as they appear in the toolbar, ignoring the case. Only one exception to that: when you need to hide "Create View" which appears twice, once in "List Settings", and then in the view selector. In order to resolve this conflict, just call the function as follows: hideListViewToolbarItems("settings:create view") or hideListViewToolbarItems("view:create view").


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Egypt Egypt
Ayman El-Hattab is a Regional Technology Solution Professional focusing on helping software professionals and organizations build better SharePoint Solutions using Microsoft Application Lifecycle Management (ALM) technologies and tools. Ayman has been in this role since 2010 and has presented at many conferences all over the Middle East & Africa about ALM, SharePoint, C#, and Business Intelligence technologies. Ayman is also a Microsoft Most Valuable Professional [SharePoint MVP] , ALM Ranger, published author and an enthusiastic speaker who enjoys working with the online and offline developer communities all over the world. Ayman is the founder of MEA ALM Community & SharePoint4Arabs, community lead at Egypt SharePoint User Group and an organizer of several SharePoint Saturday events. Outside of work, Ayman can be found watching soccer games, playing xbox or watching documentary movies.

Comments and Discussions

Questionyour email Pin
qudsia_alvi17-Sep-12 8:08
Memberqudsia_alvi17-Sep-12 8:08 
QuestionSharePoint Customization Pin
Elviraosta16-Aug-11 20:05
MemberElviraosta16-Aug-11 20:05 
QuestionCan this be applied on List View Web Part Pin
colecg10-Sep-10 0:54
Membercolecg10-Sep-10 0:54 
AnswerRe: Can this be applied on List View Web Part Pin
colecg10-Sep-10 2:32
Membercolecg10-Sep-10 2:32 
GeneralNot able to get it to work. Pin
TomBrophy28-Jan-10 7:14
MemberTomBrophy28-Jan-10 7:14 
GeneralCannot remove "New" options in document library Pin
NancyCentury25-Sep-09 4:15
MemberNancyCentury25-Sep-09 4:15 
GeneralRe: Cannot remove "New" options in document library Pin
NancyCentury29-Oct-09 5:07
MemberNancyCentury29-Oct-09 5:07 
QuestionThis script doesn't work. Pin
Nitin J. Jain22-Aug-09 1:00
professionalNitin J. Jain22-Aug-09 1:00 
AnswerRe: This script doesn't work. Pin
Ayman M. El-Hattab22-Aug-09 6:09
MemberAyman M. El-Hattab22-Aug-09 6:09 
GeneralRe: This script doesn't work. Pin
Nitin J. Jain25-Aug-09 2:06
professionalNitin J. Jain25-Aug-09 2:06 
GeneralRe: This script doesn't work. Pin
Ayman M. El-Hattab29-Aug-09 5:37
MemberAyman M. El-Hattab29-Aug-09 5:37 
GeneralThe script don't work in my Custom List View Web Part Pin
Member 418415015-May-09 4:40
MemberMember 418415015-May-09 4:40 
GeneralRe: The script don't work in my Custom List View Web Part Pin
Ayman M. El-Hattab15-May-09 5:47
MemberAyman M. El-Hattab15-May-09 5:47 
GeneralSharePoint Customization Tricks - Part 1 Pin
ella0216-Apr-09 5:27
Memberella0216-Apr-09 5:27 
GeneralRe: SharePoint Customization Tricks - Part 1 Pin
Ayman M. El-Hattab16-Apr-09 12:31
MemberAyman M. El-Hattab16-Apr-09 12:31 
GeneralPartially working... Pin
Damian Thomas10-Apr-09 6:28
MemberDamian Thomas10-Apr-09 6:28 
GeneralRe: Partially working... Pin
Ayman M. El-Hattab10-Apr-09 14:03
MemberAyman M. El-Hattab10-Apr-09 14:03 
QuestionWhat about the top level buttons or menu header Pin
bvander3-Apr-09 11:43
Memberbvander3-Apr-09 11:43 
AnswerRe: What about the top level buttons or menu header Pin
bvander3-Apr-09 11:50
Memberbvander3-Apr-09 11:50 
GeneralRe: What about the top level buttons or menu header Pin
cbennett51998-Mar-10 10:16
Membercbennett51998-Mar-10 10:16 
Generalconnect to outlook does not hide Pin
b4ck.tr4ck12-Mar-09 7:16
Memberb4ck.tr4ck12-Mar-09 7:16 
GeneralRe: connect to outlook does not hide Pin
Deependra Tandukar26-Mar-09 0:12
MemberDeependra Tandukar26-Mar-09 0:12 
GeneralRe: connect to outlook does not hide Pin
Ayman M. El-Hattab30-Aug-09 2:36
MemberAyman M. El-Hattab30-Aug-09 2:36 
QuestionRe: connect to outlook does not hide Pin
colecg12-Sep-10 23:41
Membercolecg12-Sep-10 23:41 
GeneralRe: connect to outlook does not hide Pin
Ray Escamilla24-Feb-10 9:10
MemberRay Escamilla24-Feb-10 9:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.