1

如何在 SharePoint 的列表或文档库中隐藏新建/操作/上传/设置菜单?请注意,我需要能够隐藏特定列表定义(模板)的这些菜单,而不仅仅是所有列表或文档库。

我知道的一种可能的方法是注册一个,并将 ControlClass 元素设置为从 WebControl 继承的控件。在 WebControl 中,我可以覆盖 OnPreRender,然后执行以下操作:

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

    // etc
}

这很hacky,我只是想知道是否有更好的方法?

4

4 回答 4

1

您可以使用属于 SharePoint 2007 功能 Codeplex 项目的工具栏管理器 Web 部件来实现此目的。 http://features.codeplex.com/

您需要将 Web 部件添加到每个视图网页,但它允许您隐藏菜单项而无需编码。

如果某些用户需要菜单项,请授予他们添加个人视图的权限。当他们创建个人视图时,默认情况下不会安装 Web 部件。同样,您将需要禁止不应访问菜单项的用户的个人视图。

于 2010-10-01T13:47:38.193 回答
0

我刚刚在这里写了一篇博客文章,它为你隐藏了按钮。希望能帮助到你。

于 2009-11-13T02:52:32.430 回答
0

JavaScript 可能是您最好的选择。只需修改并在您的母版页中引用此代码:

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]);
               }
          }                  
    }
}
于 2009-07-22T16:09:11.560 回答
0

如果您的列表中没有任何非隐藏的内容类型,“新建”按钮将自动消失。

于 2010-05-17T11:12:35.877 回答