SharePoint 2013 自定义扩展菜单

时间:2023-02-03 21:58:59

  在对SharePoint进行开发或者功能扩展的时候,经常需要对一些默认的菜单进行扩展,以使我们开发的东西更适合SharePoint本身的样式。SharePoint的各种功能菜单,像网站设置、Ribbon、列表里的下拉等等,都是一样原理的,都是XML+JS脚本实现的,如果想实现这些功能,只需要一个XML发布成Feature,并在网站功能启用,即可。

  其实,关于这个并没有什么过多可以说的东西,大家在实践中,渐渐理解了。下面,我就举几个简单的例子,做一下简要说明。

项目结构

  新建一个空白的SharePoint 2013项目,添加一个Feature文件,一个菜单定义的XML文件,如下图。

SharePoint 2013 自定义扩展菜单

  XML菜单定义,如下图:

SharePoint 2013 自定义扩展菜单

 

例一:扩展wssuc:Welcome控件

扩展前截图:

SharePoint 2013 自定义扩展菜单

扩展后截图:

SharePoint 2013 自定义扩展菜单

扩展XML:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id
="MyTopMenuLink"
Location
="Microsoft.SharePoint.StandardMenu"
GroupId
="PersonalActions"
Sequence
="0"
Title
="博客园-霖雨">
<UrlAction Url="http://www.cnblogs.com/jianyus"/>
</CustomAction>
</Elements>


例二 扩展SiteAction(网站设置)菜单

扩展前截图

SharePoint 2013 自定义扩展菜单

扩展后截图

SharePoint 2013 自定义扩展菜单

扩展XML

  <CustomAction
Id
="MyTopMenuLink"
Location
="Microsoft.SharePoint.StandardMenu"
GroupId
="SiteActions"
Sequence
="0"
Title
="博客园-霖雨">
<UrlAction Url="http://www.cnblogs.com/jianyus"/>
</CustomAction>

 

例三 扩展网站设置菜单

扩展后截图

SharePoint 2013 自定义扩展菜单

扩展XML

  <CustomAction
Id
="MyTopMenuLink"
Location
="Microsoft.SharePoint.SiteSettings"
GroupId
="Customization"
Sequence
="106"
Title
="博客园-霖雨">
<UrlAction Url="http://www.cnblogs.com/jianyus"/>
</CustomAction>

  网站设置菜单,不仅仅可以通过GroupId设置显示在哪个位置,还可以单独添加一个Group,后面我们会举例说明。

至于GroupId选择哪一个,请参考附后的MSDN文档。

 

例四 扩展文档库Ribbon菜单

扩展后截图

SharePoint 2013 自定义扩展菜单

扩展XML

  <CustomAction
Id
="MyTopMenuLink"
Location
="Microsoft.SharePoint.StandardMenu"
GroupId
="SettingsMenu"
RegistrationType
="List"
RegistrationId
="101"
Sequence
="0"
Title
="博客园-霖雨">
<UrlAction Url="http://www.cnblogs.com/jianyus"/>
</CustomAction>

  RegistrationId可以区分是文档库,还是列表库,是TemplateID

 

例五 扩展文档库ECB菜单

扩展后截图

SharePoint 2013 自定义扩展菜单

扩展XML

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id
="MyTopMenuLink"
Location
="EditControlBlock"
RegistrationType
="List"
RegistrationId
="101"
Sequence
="0"
Title
="博客园-霖雨">
<UrlAction Url="http://www.cnblogs.com/jianyus"/>
</CustomAction>
</Elements>

  如上图,因为Sequence是0,所以这个菜单在最上面,如果想要移动位置,设置这个值即可。

 

例六 扩展网站操作组

扩展后截图

SharePoint 2013 自定义扩展菜单

扩展XML

  <!-- Custom Action Group -->
<CustomActionGroup
Id
="CustomActionGroup"
Description
="自定义组"
Title
="我的自定义组"
Location
="Microsoft.SharePoint.SiteSettings"
Sequence
="30" />

<!-- Custom Action in Custom Action Group -->
<CustomAction
Id
="CustomAction1"
Description
="自定义操作"
Title
="自定义操作一"
GroupId
="CustomActionGroup"
Location
="Microsoft.SharePoint.SiteSettings"
Rights
="ManageWeb"
RequireSiteAdministrator
="FALSE"
Sequence
="20">
<UrlAction Url="~sitecollection/_layouts/CustomAction1.aspx" />
</CustomAction>

<CustomAction
Id
="CustomAction2"
Description
="自定义操作"
Title
="自定义操作二"
GroupId
="CustomActionGroup"
Location
="Microsoft.SharePoint.SiteSettings"
Rights
="ManageWeb"
RequireSiteAdministrator
="FALSE"
Sequence
="20">
<UrlAction Url="~sitecollection/_layouts/CustomAction2.aspx" />
</CustomAction>

  如上图,添加了网站操作组,可以用来添加我们的设置。在2013之前版本,类似SiteAction等,都可以进行分组,但是2013我尝试了一下,分组没有成功。而且,之前版本的网站设置,都是菜单分组的形式;新版本默认都没有分组,是否支持还有待进一步研究。

后记

  以上,是几个简单的扩展菜单例子,主要还是修改GroupId和Location来确定菜单的显示位置,通过Rights来限制权限,Sequence来设置排序等,更多的扩展,请参考MSDN自行尝试。

参考MSND链接

1、Default Custom Action Locations and IDs

http://msdn.microsoft.com/en-us/library/bb802730.aspx

2、Custom Actions and Ribbons

http://www.matthiaseinig.de/docs/SPSF/OutputHTML/SPSF_RECIPES_CATEGORY_CUSTOMACTIONS.html

3、SharePoint 2013 自定义扩展菜单(二)

包含另外三个例子,列表设置、管理中心、人员和组添加菜单