Click here to Skip to main content
Click here to Skip to main content

SharePoint Customization Tricks - Part 1

By , 18 Jan 2009
 

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 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#, asp.net 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.

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.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionyour emailmemberqudsia_alvi17 Sep '12 - 7:08 
Hi,
is it possible that you may give me your email. I wanna learn share point out of box solutions.
Thanks
qudsia
QuestionSharePoint CustomizationmemberElviraosta16 Aug '11 - 19:05 
I have gone through all the discussion over all its good, I just want to know that few tools that are available in the market (3rd party products) that claim to optimize/customize SharePoint while enhancing sharepoint performance like there is a tool known as StorageEdge with instant free download at http://www.alachisoft.com/storageedge/storageedge-express.html[^] and there are several other tools which claims the same, what do you think about them? are these tools the easy solution for customizing sharepoint?
QuestionCan this be applied on List View Web Partmembercolecg9 Sep '10 - 23:54 
I have tried using your java script methods on List View Web Part, but did not have success.
Can this be applied to it or do you know what do I have to change or where to look for differences in your code between List View and List Form?
Thank you in advance,
Amira
COLECG

AnswerRe: Can this be applied on List View Web Partmembercolecg10 Sep '10 - 1:32 
I got it to work
I did not inlude <script><\script> in my CEWB and that is why it did not take effect.
Thank you
COLECG

GeneralNot able to get it to work.memberTomBrophy28 Jan '10 - 6:14 
I've created a hidden CEWP under the list web part. I inserted the following code into the 'source editor' of the content editor web part. This is an exact duplicate of your sample code with the script header and footer. The menu items appear exactly the same - it appears to not change/hide anything. I also tried doing only a couple of menu items but nothing ever changes in the menu.
 
Any ideas?
 
Thanks,
 
Tom
 

 
<script type="text/javascript" language="javascript">
 
hideListViewToolbarItems("Edit in Datasheet", "export to Spreadsheet", "view rss feed","settings:create view");
 
function hideListViewToolbarItems()
{
///
/// By : Ayman M. El-Hattab ( ayman.elhattab@gmail.com )
/// http://ayman-elhattab.blogspot.com
///


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;
}
}
}
}
</script>
GeneralCannot remove "New" options in document librarymemberNancyCentury25 Sep '09 - 3:15 
Despite all my efforts with your great code, I can't get "New" button or "create new item" drop-down to disable in my document library toolbar. Is there some trick to this? Every other toolbar option I want to remove succumbs to your code. What's special about "New"?
GeneralRe: Cannot remove "New" options in document librarymemberNancyCentury29 Oct '09 - 4:07 
I also want to remove "Connect to Outlook" and this one won't go away either.
QuestionThis script doesn't work.memberjain_nitin22 Aug '09 - 0:00 
Hi,
 
Its great article, but unfortunatly it doesn't work for me.
 
I add this script to head section of my site master page.
 
I debugged this script and found that document.getelementbyTagId
 
('ie:menuitem')
return zero items. and its the reson that for loop is
 
not worked. Can you please help me about this?
AnswerRe: This script doesn't work.memberAyman M. El-Hattab22 Aug '09 - 5:09 
Hi there,
please use the instructions in Part 2 of the series Smile | :)
You need to add the script either in a CEWP below the ListViewWebPart on before </body> in the master page.
Let me know if you need further help. Smile | :)
 
www.aymanelhattab.com
 
Ayman M. El-Hattab
Microsoft Certified SharePoint Specialist
ITWorx Egypt
http://ayman-elhattab.blogspot.com

GeneralRe: This script doesn't work.memberjain_nitin25 Aug '09 - 1:06 
Hi,
 
Its work for me now. But i have one problem i.e. Once the items are
 
removed from toolbar and after that if i delete the javascript from the
 
master page. Although menus which are remove by script dont visible. Its
 
permanantly removed from the toolbar. Even though i try on newly created
 
Sharepoint List, but here also menu's are not visible. How can i make
 
menu visible again?
 
Its very urgent.....
GeneralRe: This script doesn't work.memberAyman M. El-Hattab29 Aug '09 - 4:37 
I didn't get you, Please clarify Smile | :)
 
Ayman M. El-Hattab
Microsoft Certified SharePoint Specialist
ITWorx Egypt
http://ayman-elhattab.blogspot.com

GeneralThe script don't work in my Custom List View Web PartmemberMarcio Bulzico15 May '09 - 3:40 
Hi, i put your javascript in a CEWP above of the my Custom List View Web Part.
 
but don't work, the New Item Menu still appear.
 
Other question:
 
I can call the Javascript in the code of my Custom List View Web Part?
 
If yes, how to do?
 
Thanks for help,
 
Congratulations for your work!!!
 
Marcio Bulzico - .NET and Sharepoint Developer
GeneralRe: The script don't work in my Custom List View Web PartmemberAyman M. El-Hattab15 May '09 - 4:47 
This script is designed and tested for List Form Web Part and now DataFormWebPart.
I'm afraid but I promise to create another one for the Custom Data View Web Part as soon as I have time Smile | :)
Thanks for your comments
 
Ayman M. El-Hattab
Microsoft Certified SharePoint Specialist
ITWorx Egypt
http://ayman-elhattab.blogspot.com

GeneralSharePoint Customization Tricks - Part 1memberella0216 Apr '09 - 4:27 
Hi,
 
The code doesnt work when I try to hide Print List mneu. Any idea why?
 
Thanks.
GeneralRe: SharePoint Customization Tricks - Part 1memberAyman M. El-Hattab16 Apr '09 - 11:31 
check Part 2 of the series Smile | :) it'll help you to getting the script to work
 
Ayman M. El-Hattab
Microsoft Certified SharePoint Specialist
ITWorx Egypt
http://ayman-elhattab.blogspot.com

GeneralPartially working...memberDamian Thomas10 Apr '09 - 5:28 
Hello there,
Thank you for posting this information. We have gotten some of the menu items to hide while others are not. Specifically, within the picture library, we are unable to hide EDIT, DELETE, DOWNLOAD, and SEND TO. Also, CONNECT TO OUTLOOK will not hide anywhere within our site. Ideas???
GeneralRe: Partially working...memberAyman M. El-Hattab10 Apr '09 - 13:03 
Damian,
I'm glad that you liked the post. You can edit the javascript code to hide whatever you want Smile | :) It's very easy, give it a shot and tell me if you need any help. You can follow me at twitter http://www.twitter.com/aymanelhattab
 
Ayman M. El-Hattab
Microsoft Certified SharePoint Specialist
ITWorx Egypt
http://ayman-elhattab.blogspot.com

QuestionWhat about the top level buttons or menu headermemberbvander3 Apr '09 - 10:43 
The script pulled the "upload docuemtn" and Upload Multiple documents" just fine, but it didn't get rid of the "Upload" menu button.
 
I tried using the Tip 2 script to get rid of it but that only works for a form.
AnswerRe: What about the top level buttons or menu headermemberbvander3 Apr '09 - 10:50 
awesome post by the way!!!!!
GeneralRe: What about the top level buttons or menu headermembercbennett51998 Mar '10 - 9:16 
Did you ever get this to work? I'm looking for the same solution.
Generalconnect to outlook does not hidememberb4ck.tr4ck12 Mar '09 - 6:16 
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 hidememberDeependra Tandukar25 Mar '09 - 23:12 
somehow this doesn't work - connect to outlook...
GeneralRe: connect to outlook does not hidememberAyman M. El-Hattab30 Aug '09 - 1:36 
Refer to the second part of the series for more info Smile | :)
 
Ayman M. El-Hattab
Microsoft Certified SharePoint Specialist
ITWorx Egypt
http://ayman-elhattab.blogspot.com

QuestionRe: connect to outlook does not hidemembercolecg12 Sep '10 - 22:41 
I still do not understand where to look for solution on how to hide "connect to outlook" in the second part?
Can you please help?
Thanks in advance
COLECG

GeneralRe: connect to outlook does not hidememberRay Escamilla24 Feb '10 - 8:10 
Remember ECB (Context Menu) items are generated from core.js. You'll need to first implement a custom core.js per this blog posting and then comment out the method call
AddWorkOfflineMenuItem(m, ctx, currentItemFileUrl)

Generalplease can you tell us how to use this scripts ...memberjacobsaumy12 Feb '09 - 3:23 
Thanx for this scripts .. but if you can tell us how to use this scripts, where to add them ...
 
jacobsaumy

GeneralRe: please can you tell us how to use this scripts ...memberAyman M. El-Hattab12 Feb '09 - 4:32 
Refer to Trick 3 in Part 2 Smile | :)
Thanks
 
Ayman M. El-Hattab
Microsoft Certified SharePoint Specialist
ITWorx Egypt
http://ayman-elhattab.blogspot.com

GeneralRe:memberramup33315 Jul '09 - 23:43 
Hi Ayman,
Can u please tell me jow to hide the entire toolbar itself in Sharepoint list "AllItems.aspx page.
 
Thanks,
Ram
GeneralRe:memberAyman M. El-Hattab17 Jul '09 - 2:59 
Ram,
Refer to the second part of the series and let me know if you need any further help.
 
Ayman M. El-Hattab
Microsoft Certified SharePoint Specialist
ITWorx Egypt
http://ayman-elhattab.blogspot.com

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

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