views:

7643

answers:

7

How can I hide the New / Actions / Upload / Settings menus within a list or document library in SharePoint? Note that I need to be able to hide these menus for a particular list definition (template) and not just all lists or document libraries.

One possible way that I know of is to register a , and set the ControlClass element to a control that inherits from WebControl. In the WebControl, I can override OnPreRender, which then does this:

foreach (Control control in this.Parent.Controls)
{
    if (control.ToString() == "Microsoft.SharePoint.WebControls.NewMenu")
    {
        control.Visible = false;
    }

    // etc
}

This is pretty hacky, and I was just wondering if there is a better way of doing it?

A: 

JavaScript is probably your best option. Just modify and refer to this code in your Master Page:

hideListViewToolbarItems("list settings","document library settings","create column","open with windows explorer");

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; 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]);
               }
          }                  
    }
}
Ajay Nayak
A: 

I need to disable new item creation (new document) in a specific document library.

I would like to remove the button completely if possible, but will settle for disabling it by eliminating the "Create a new document" dropdown as well as the on-click function of the New button itself.

The code above does not perform these removals, no matter how I configure it using the "new document" or "new item" menu item names in the function. All the others work fine but I cannot get "New" to go away.

Any help is appreciated!

Nancy
@Nancy: If you have a new question, please ask it as a new question. You can refer back to this question to provide context.
Alex Angas
A: 

I just wrote a blog entry here on this which hides the button for you. Hope it helps.

Bil
A: 

If the ListMenuWebpart has to be hidden for some specified users, how can i get it done. Can anyone please help me out in this

reshma
A: 

If you don't have any non-hidden content types in your list, the "new" button will automatically disappear.

A: 

You can acheive this using the Toolbar Manager web part that is part of the SharePoint 2007 Features Codeplex project. http://features.codeplex.com/

You need to add the web part to the each view web page, but it allows you to hide menu items without coding.

If some users need the menu item, give them permission to add personal views. When they create a personal view, the web part will not be installed by default. As well, you will need to disallow personal views for users that should not be to access the menu items.

Ken Munro