sharepoint 2010如何隐藏.添加.禁用.Ribbon菜单中的项,多个方法
1. 一个是比较简单的就是在管理中心设置下,http://管理中心地址/_admin/vsmask.aspx下会显示列表权限、网站权限、个人权限,根据需要显示相应的项。
2. 就是通过操作代码操作xml里面的项,在Ribbon菜单里添加自定义Button。
新建项目》添加空元素》在xml里面写,
<CustomAction
Id="CustomRibbonButton"
RegistrationId="101"
RegistrationType="List"
Location="CommandUI.Ribbon"
Sequence="5"
Title="Move Documents">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.Documents.Manage.Controls._children">
<Button
Id="Ribbon.Documents.New.TestButton"
Alt="show Mesage"
Sequence="5"
Command="Test_Button"
Image32by32="/_layouts/images/spInfo/3232.GIF"
Image16by16="/_layouts/images/spInfo/1616.GIF"
LabelText="Move Documents"
TemplateAlias="o1" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="Test_Button"
CommandAction="javascript:alert('helloword');" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
效果图:
![sharepoint 2010如何隐藏.添加.禁用.Ribbon菜单中的项,多个方法 - vickynuli - vickynuli的博客](http://img1.ph.126.net/G24jLPCHbwIbPg3lKnfgCg==/3071173470907581081.jpg)
PS:![sharepoint 2010如何隐藏.添加.禁用.Ribbon菜单中的项,多个方法 - vickynuli - vickynuli的博客](http://b.bst.126.net/common/portrait/g/preview/g14.gif)
![sharepoint 2010如何隐藏.添加.禁用.Ribbon菜单中的项,多个方法 - vickynuli - vickynuli的博客](http://b.bst.126.net/common/portrait/g/preview/g14.gif)
CustomAction 部分:
RegistrationType:看完了下面那个链接,觉得RegistrationType和RegistrationId可以只写一个,
RegistrationId(101所代表的数值为文档库,这个链接里面例举出所有的相对应的数据):http://vickynuli.blog.163.com/blog/static/18043849220127222311233/
Location:该按钮应该放在tab下的哪个组,
Sequence:数字代表把该按钮所存放的位置,TemplateAlias:定义该图片是32x32还是16x16,o1代表32,o2代表16
3. 隐藏Ribbon部分功能
3.1. 新建用户控件
3.2. 引用C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.Web.CommandUI.dll
using System.Microsoft.SharePoint.WebControls;
3.3 接着在用户控件的load里面写代码,根据需要隐藏相关控件,
SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);
if (ribbon != null)
{
ribbon.TrimById("Ribbon.Documents.New.NewFolder");
ribbon.TrimById("Ribbon.Documents.Manage.Delete");
ribbon.TrimById("Ribbon.Library.Share.EmailLibraryLink");
}
3.4. 部署即可,
3.5. 用sharepoint design打开部署的站点,在模板页页面,引用该用户控件 ,
![sharepoint 2010如何隐藏.添加.禁用.Ribbon菜单中的项,多个方法 - vickynuli - vickynuli的博客](http://img8.ph.126.net/uDMAeMZDBBvorTSgrpJIAA==/6597375430889669058.jpg)
接着在body里面引用,
![sharepoint 2010如何隐藏.添加.禁用.Ribbon菜单中的项,多个方法 - vickynuli - vickynuli的博客](http://img9.ph.126.net/wo_-gcCufyEJL0Omx17pjA==/6597428207446791279.jpg)
最后就可以查看结果了(下图知道哪几个隐藏了吗?自己找吧,
)。
![sharepoint 2010如何隐藏.添加.禁用.Ribbon菜单中的项,多个方法 - vickynuli - vickynuli的博客](http://b.bst.126.net/common/portrait/face/preview/face19.gif)
![sharepoint 2010如何隐藏.添加.禁用.Ribbon菜单中的项,多个方法 - vickynuli - vickynuli的博客](http://b.bst.126.net/common/portrait/r/preview/r7.gif)
![sharepoint 2010如何隐藏.添加.禁用.Ribbon菜单中的项,多个方法 - vickynuli - vickynuli的博客](http://img4.ph.126.net/Om9BJ2h28Rj-8xEZnA3rWQ==/6597390824052455964.jpg)
![sharepoint 2010如何隐藏.添加.禁用.Ribbon菜单中的项,多个方法 - vickynuli - vickynuli的博客](http://img8.ph.126.net/HwaR7vlnlgK8NUEMe5hcfg==/6597431505981676168.jpg)
PS:
这里需要注意一个问题,在sharepoint里面,有分为列表、文档、网页、库、网站等,所对应的属性也不同,如以下代码的加粗部分,这里仅仅只针对文档库有效,所以如果在其他地方没有效果时,得查看Id是否是正确的,
这里还需要说下,TrimById只是动态隐藏,而不是删除,所以注释再部署之后,该按钮会再次出现。
ribbon.TrimById("Ribbon.Documents.New.NewFolder");
ribbon.TrimById("Ribbon.Documents.Manage.Delete");
ribbon.TrimById("Ribbon.Library.Share.EmailLibraryLink");
4. 这个是msdn上的文章,反正在我的环境试了,没什么效果,就下面这几段代码,我试了反正不行,不知道怎么回事(真的没什么效果,哪位大神救救)。![sharepoint 2010如何隐藏.添加.禁用.Ribbon菜单中的项,多个方法 - vickynuli - vickynuli的博客](http://b.bst.126.net/common/portrait/bear/preview/bear6.gif)
![sharepoint 2010如何隐藏.添加.禁用.Ribbon菜单中的项,多个方法 - vickynuli - vickynuli的博客](http://b.bst.126.net/common/portrait/bear/preview/bear6.gif)
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <CustomAction Id="RemoveRibbonButton" Location="CommandUI.Ribbon"> <CommandUIExtension> <CommandUIDefinitions> <CommandUIDefinition Location="Ribbon.Library.Actions.ConnectToClient" /> </CommandUIDefinitions> </CommandUIExtension> </CustomAction> </Elements>