Blue Theme Orange Theme Green Theme Red Theme
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
6 Months Free & No Setup Fees ASP.NET Hosting!
Search :       Advanced Search »
Home » SharePoint » SharePoint Customization Tricks: Part I

SharePoint Customization Tricks: Part I

This multipart series of articles is intended to help you get ramped up with SharePoint customizations. In this article we will see how to hide List View Toolbar Menu Items.

Page Views : 12599
Downloads : 175
Rating :
 Rate it
Level : Intermediate
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
hideListViewToolbarItems.zip
 
 
Discover the top 5 tips for understanding .NET Interop
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


This multipart series of articles is intended to help you getting ramped up with SharePoint Customization. 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 prerequisite 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 List View Toolbar Menu Items!

hideListViewToolbarItems1.jpg 

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" feature framework such as Site Actions and Site setting.... etc.
  • ECB (Context Menu) items are rendered by JavaScript from Core.js file so we can't hide them via "HideCustomAction" feature. However, you can add a new menu item in the ECB menu through "CustomAction" feature and hide it again through The "HideCustomAction" feature. In other words," 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()
{       

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;jif(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]);
                   }
          }                 
}

}

You can use this function to hide any menu items 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 one in "List Settings" and the other one 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")

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Ayman ElHattab
Ayman M. El-Hattab works in ITWorx as a Software Engineer since October 2008, and since then has been working on building solutions using Microsoft Office, SharePoint 2007, .NET Framework 2.0/3.0/3.5, Microsoft SQL Server, C#, XML, Exchange, ASP.NET and others.

Ayman holds a Bachelor of Engineering degree in Mechatronics Engineering from Ain Shams University, and is a Microsoft Certified Application Developer, Solution Developer, SharePoint 2007 Specialist and Sun Certified Java Programmer.

Prior to ITWorx, Ayman worked for Asset Technology Group, NRG Solutions and he used to deliver courses for Mechatronics engineers (Robotics, Automatic Control, Artificial Intelligence, Image Processing and Data Acquisition courses). Ayman is a soccer fanatic and he supports Ahly FC and Barcelona FC.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the Top 5 .NET Memory Management Fundamentals
To write the best .NET code, you need to know exactly how the .NET framework really manages memory. Ricky Leeks presents the Top 5 fundamental facts of .NET memory management. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Comments
Not working by dinesh On February 10, 2009
The above feature is not working
Reply | Email | Modify 
Re: Not working by Ayman On February 11, 2009

Tell me, How did you inject JavaScript into the page ?

Refer to Part 2 in the series for more info

and let me know if you need any help

Reply | Email | Modify 
Re: Re: Not working by dinesh On February 11, 2009

I followed the same step mentioned in Part II of the article.

1. Added one content editor web part in the list.

2. Added the javascript code in the source editor.

when i try to view the actions link, there is no change, all the default options are displaying.

below is the code added to source editor.

<script language="javascript" type="text/javascript">

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

function hideListViewToolbarItems()
{       

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;jif(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]);
                   }
          }                 
}

}

</script>

Reply | Email | Modify 
Re: Re: Re: Not working by Ayman On February 11, 2009
please Use the function in the zip file and make sure that you insert the Content Editor Web Part below the list view web part and not above it as shown in Part 2.
Reply | Email | Modify 
Re: Re: Re: Re: Not working by dinesh On February 11, 2009
Thanks a lot, its working fine. Very Good article.
Reply | Email | Modify 
Re: Re: Re: Re: Re: Not working by Ayman On February 11, 2009

you are welcome :)

I'm glad you liked it

Was the problem in the place of the CEWP ?

Reply | Email | Modify 
Re: Re: Re: Re: Re: Re: Not working by dinesh On February 11, 2009

It was not the problem of CEWP. Yesterday i tried the same steps. it did not work. Today I again downloaded and tried it' working.

Thanka a lot.

 

Reply | Email | Modify 
Re: Re: Re: Re: Re: Re: Not working by dinesh On February 11, 2009
There is one more issue. Connect to Outlook option is not getting removed. All other options can be removed. Please check.
Reply | Email | Modify 
Re: Re: Re: Re: Re: Re: Re: Not working by Stephen On February 18, 2009

I see that this is working but I was having some issues getting the View to remove the All Documents and Explorer View entries to go away, could I be doing something wrong?

I am using the following code below:

hideListViewToolbarItems("view:create view","all documents");

Reply | Email | Modify 
Incomplete Solution!!! by Stephen On February 18, 2009

While this works for 98% of the menu items it will not work as written for Views if you are using new default views. In order to make this work when you have created a view and marked it as default a few things must be cleared up:

1. The menu items marks the first default view as menuitem="defaultview".

 2. The code above , as written , will assume the first default view is the original default view.

In order to fix the code you may have to actually look at your source code after the page has been rendered to make the approriate associations and changes to the array.

As you can see in the code posted below I had to use View1 and View2 with the correct ItemName associations to get the actual menu item to hide. Generally a default view that you create and mark as default will cause the old default view to be called View1, then the next View to be View 2, etc.etc.

 Anyway, just modify the array after determining your view order and it should work properly. Again, this i sonly needed if you are using custom default views and not the standard default view.

For example:)

 

 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", "all documents", "explorer view", "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", "View2", "DefaultView", "ModifyView", "CreateView", "New0", "New0", "NewFolder", "Upload", "MultipleUpload" );

Reply | Email | Modify 
Hide the author by Jason On March 31, 2009
Is there a similar method to hide the author of an item?
Reply | Email | Modify 
good though by Urvi On May 7, 2009
it is indeed informative one..looking forward to have more information about javascript. I just love to involve in coding
Reply | Email | Modify 
startup kit --confused by Urvi On May 7, 2009

Hello Ayman, I got the coding stuff but as I used this javascript exercise before 5  years so suddenly I wiped out my knowledge could you please let me know, how to execute this coding and what sort of platforms I have to have in my computer...plzz help me out..ASAP.

Reply | Email | Modify 
Thanks a lot! by valli On July 15, 2009
Hello Ayman,
                    This is really helpful. Thanks a lot.

Bhuvan
Reply | Email | Modify 
Can't hide the List Settings Button by scott On October 14, 2009
 I have been trying to get this to work with no luck. All I need is to hide the llist setting button.

Any help would be appreciated.

Scott.Muldowney@bankofamerica.com
Reply | Email | Modify 
Thanks for the code! by stan On October 19, 2011
It works for me! Thanks!
Reply | Email | Modify 
Thanks for the code! by stan On October 19, 2011
It works for me! Thanks!
Reply | Email | Modify 
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.