Click here to Skip to main content
Licence CPOL
First Posted 18 Jan 2009
Views 43,641
Downloads 91
Bookmarked 25 times

SharePoint Customization Tricks - Part 1

By | 18 Jan 2009 | Article
Trick #1: Hiding the list view toolbar menu items!

Introduction

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.

Prerequisites

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!

hideListViewToolbarItems

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 ( ayman.elhattab@gmail.com )
	/// http://ayman-elhattab.blogspot.com
	/// </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", 
	  "OpenInExplorer","OfflineButton",
	  "ExportToSpreadsheet","ViewRSS",
	  "SubscribeButton","AddColumn",
	  "AddView","ListSettings","ListSettings", 
	  "View1","DefaultView",
	  "DefaultView","ModifyView","CreateView", 
	  "New0","New0",
	  "NewFolder","Upload","MultipleUpload");		

	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++) 
		{
			if(menuItemNames[j]==menuItemName)
			{				
				menuItemIndex = j;
				break;
			}
		}

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

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").

License

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

About the Author

Ayman M. El-Hattab

Architect

Egypt Egypt

Member

Ayman El-Hattab is a SharePoint MVP, Developer, Author & Speaker. He is a Microsoft Certified Solution Developer as well as a Microsoft Certified Technology Specialist in SharePoint. Ayman writes articles about topics in relation to SharePoint and its related technologies for online magazines, publicly speaks for numerous user groups, offline communities and SharePoint Saturdays, is the founder of www.SharePoint4Arabs.com, organizes events for Egypt SharePoint User Group and you will always find him active at MSDN and Technet forums. Ayman has also been recognized by Microsoft as Most Valuable Professional (MVP) in April 2010.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionSharePoint Customization PinmemberElviraosta19:05 16 Aug '11  
QuestionCan this be applied on List View Web Part Pinmembercolecg23:54 9 Sep '10  
AnswerRe: Can this be applied on List View Web Part Pinmembercolecg1:32 10 Sep '10  
GeneralNot able to get it to work. PinmemberTomBrophy6:14 28 Jan '10  
GeneralCannot remove "New" options in document library PinmemberNancyCentury3:15 25 Sep '09  
GeneralRe: Cannot remove "New" options in document library PinmemberNancyCentury4:07 29 Oct '09  
QuestionThis script doesn't work. Pinmemberjain_nitin0:00 22 Aug '09  
AnswerRe: This script doesn't work. PinmemberAyman M. El-Hattab5:09 22 Aug '09  
GeneralRe: This script doesn't work. Pinmemberjain_nitin1:06 25 Aug '09  
GeneralRe: This script doesn't work. PinmemberAyman M. El-Hattab4:37 29 Aug '09  
GeneralThe script don't work in my Custom List View Web Part PinmemberMarcio Bulzico3:40 15 May '09  
GeneralRe: The script don't work in my Custom List View Web Part PinmemberAyman M. El-Hattab4:47 15 May '09  
GeneralSharePoint Customization Tricks - Part 1 Pinmemberella024:27 16 Apr '09  
GeneralRe: SharePoint Customization Tricks - Part 1 PinmemberAyman M. El-Hattab11:31 16 Apr '09  
GeneralPartially working... PinmemberDamian Thomas5:28 10 Apr '09  
GeneralRe: Partially working... PinmemberAyman M. El-Hattab13:03 10 Apr '09  
QuestionWhat about the top level buttons or menu header Pinmemberbvander10:43 3 Apr '09  
AnswerRe: What about the top level buttons or menu header Pinmemberbvander10:50 3 Apr '09  
GeneralRe: What about the top level buttons or menu header Pinmembercbennett51999:16 8 Mar '10  
Generalconnect to outlook does not hide Pinmemberb4ck.tr4ck6:16 12 Mar '09  
Hi Ayman, and thanks for sharing this nice solution!
I have problem in hiding the Connect to Outlook button.
This is my call:
hideListViewToolbarItems("Edit in Datasheet","export to Spreadsheet","view rss feed","open with windows explorer","upload multiple documents","connect to outlook");
 
if I place "connect to outlook" as first parameter then nothing gets hidden.
I know nothing about jscript but i was wondering why some array values have quotations "" and others have apex ''
 
Another thing, it took me long to realize that the CEWP had to be under the other web part in order to make it working. Maybe it would be useful to state it in the instruction (if I missed it, my bad)
 
regards,
andrew
GeneralRe: connect to outlook does not hide PinmemberDeependra Tandukar23:12 25 Mar '09  
GeneralRe: connect to outlook does not hide PinmemberAyman M. El-Hattab1:36 30 Aug '09  
QuestionRe: connect to outlook does not hide Pinmembercolecg22:41 12 Sep '10  
GeneralRe: connect to outlook does not hide PinmemberRay Escamilla8:10 24 Feb '10  
Generalplease can you tell us how to use this scripts ... Pinmemberjacobsaumy3:23 12 Feb '09  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 18 Jan 2009
Article Copyright 2009 by Ayman M. El-Hattab
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid