在SharePoint 2010的标准菜单中添加自定义操作菜单项

在SharePoint 2010的网站操作菜单中添加一个自定义菜单项的最佳实践是通过创建一个Feature并以wsp包的形式部署到SharePoint 2010环境。

在本文中我们将讨论如何创建一个Feature和解决方案包,实现在网站操作菜单中添加自定义操作。

步骤如下:

1、在VS 2010中创建一个新项目,并在左侧分类中选择SharePoint下的空项目。

2、输入SharePoint网站的URL,以便调试和作为一个场解决方案进行部署。

3、现在,当我们有了一个打开的项目后,右击Feature文件夹来添加一个新的Feature。

4、SharePoint自动添加了一个Feature并命名为Feature1。你可以重命名,比如将这个Feature的名字改成CustomActionFeature。

5、此时你会打开一个Feature设计器界面,可以设置该Feature的标题、描述和范围。

6、右击该项目,选择添加一个新项。在添加新项对话框中,选择空元素,创建一个空白element文件。

7、添加下面的代码到element.xml文件

<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
<CustomAction
Id=”myCustomAction”
GroupId=”PersonalActions”
Location=”Microsoft.SharePoint.StandardMenu”
Sequence=”1000″
Title=”打开自定义页面”
Description=”打开我的自定义页”
ImageUrl=”_layouts/2052/images/myimage.png”>
<UrlAction Url=”~site/_layouts/CustomPage.aspx”/>
</CustomAction>
</Elements>

8、编译该项目。打开feature.xml文件,检查是否包含了到element.xml文件的引用。

9、部署该wsp,并在你的网站上进行激活。

正如上面的代码所示,为某个菜单定义一个自定义操作时,你必须首先能够标识该菜单。Location属性定义了该菜单——比如,Microsoft.SharePoint.SiteSettings或Microsoft.SharePoint.StandartMenu。GroupID属性定义了该菜单中的一个区域。

标准菜单的Location和GroupID如下表所示:

Location GroupID 描述
Microsoft.SharePoint.StandardMenu ActionsMenu 在列表\文档库视图中的操作
Microsoft.SharePoint.StandardMenu ActionsMenuForSurvey 针对调查的网站操作菜单
Microsoft.SharePoint.StandardMenu NewMenu 在列表\文档库视图中的新建菜单
Microsoft.SharePoint.StandardMenu PersonalActions 显示 “欢迎xx用户”,”登录”这些项的菜单
Microsoft.SharePoint.StandardMenu SettingsMenu 在列表\文档库视图中的设置菜单
Microsoft.SharePoint.StandardMenu SettingsMenuForSurvey 针对调查的网站设置菜单
Microsoft.SharePoint.StandardMenu  SiteActions 网站操作菜单
Microsoft.SharePoint.StandardMenu  UploadMenu 在列表\文档库视图中的上载菜单

 

参考资料

Add custom menu item in Site Actions sharepoint 2010

Location and GroupID Properties for StandardMenu - Chart

posted @ 2010-08-30 09:02  Sunmoonfire  阅读(250)  评论(0)    收藏  举报