SharePoint 2013:自定义ECB菜单项的添加
本文分别介绍了两种常用的添加ECB菜单项的方式。
声明式创建
这也是微软最佳实践推荐的方式。在VS中创建一个SharePoint空解决方案,并添加一个“空元素”类型的SPI。

在Elements.xml中,定义一个CustomAction,重点关注一下其中高亮部分的属性(本例在文档内容类型的项上添加了一个菜单项,点击导航到一个自定义应用程序页面,并传递项所在的列表的Id作为参数):

添加到Feature,并部署。效果如下:

服务器对象模型创建
这里会用到Feature的事件处理程序。本例同时还演示了如何指定Url,并且用对话框的方式打开。同时,还会传递网站Url,所选列表项的ID给目标应用程序页面。
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site = (SPSite)properties.Feature.Parent;
SPWeb web=site.RootWeb;
try{ SPList list = web.Lists["Announcements"];
web.AllowUnsafeUpdates = true;
if (list.UserCustomActions.Count > )
{
foreach (SPUserCustomAction action in list.UserCustomActions)
{
if (action.Name == "ECBItemCustomization")
{
action.Delete();
list.Update();
break;
}
}
}
SPUserCustomAction customaction = list.UserCustomActions.Add();
customaction.Name = "ECBItemCustomization";
customaction.Location = "EditControlBlock"; //customaction.ImageUrl = "/_layouts/15/images/demo/workflows.gif"; string cAction = @"javascript: var options = {
url: '{SiteUrl}' + '/_layouts/15/demo/page.aspx/?WorkItemID={ItemId}',
allowMaximize: false,
width: 500,
height: 440 };
SP.UI.ModalDialog.showModalDialog(options);";
customaction.Url = cAction;
customaction.Sequence = ;
customaction.Title = "Demo ECB Title";
customaction.Update();
list.Update();
web.AllowUnsafeUpdates = false; }
catch{ }
}
相应的,要在Feature关闭时移除我们的ECB项:
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPSite site = (SPSite)properties.Feature.Parent;
SPWeb web=site.RootWeb;
try{ SPList list = web.Lists["Announcements"];
web.AllowUnsafeUpdates = true;
if (list.UserCustomActions.Count > )
{
foreach (SPUserCustomAction action in list.UserCustomActions)
{
if (action.Name == "ECBItemCustomization")
{
action.Delete();
list.Update();
break;
}
}
} web.AllowUnsafeUpdates = false; }
catch{ }
}
为了看最终效果,添加了一个demo\page.aspx应用程序页面。接收url参数,然后显示相应的通知标题。代码比较简单,就不贴了。部署看效果:

注意:与SharePoint 2010的ECB不同的是,SharePoint 2013的ECB会忽略ImageUrl这一属性。因为从前面的图中也可以看出,2013的ECB项左侧都是不带图标的。
参考资料
how to apply custom action in ECB only for document item
Add Custom Action To SharePoint Edit Control Block
SharePoint 2013:自定义ECB菜单项的添加的更多相关文章
- SharePoint 2013 自定义扩展菜单
在对SharePoint进行开发或者功能扩展的时候,经常需要对一些默认的菜单进行扩展,以使我们开发的东西更适合SharePoint本身的样式.SharePoint的各种功能菜单,像网站设置.Ribbo ...
- SharePoint 2013 自定义扩展菜单(二)
接博文<SharePoint 2013 自定义扩展菜单>,多加了几个例子,方便大家理解. 例七 列表设置菜单扩展(listedit.aspx) 扩展效果 XML描述 <CustomA ...
- 每日学习心得:SharePoint 2013 自定义列表项添加Callout菜单项、文档关注、SharePoint服务端对象模型查询
前言: 前一段时间一直都比较忙,没有什么时间进行总结,刚好节前项目上线,同时趁着放假可以好好的对之前遇到的一些问题进行总结.主要内容有使用SharePoint服务端对象模型进行查询.为SharePoi ...
- 【FBA】SharePoint 2013自定义Providers在基于表单的身份验证(Forms-Based-Authentication)中的应用
//http://www.cnblogs.com/OceanEyes/p/custom-provider-in-sharepoint-2013-fba-authentication.html 由于项目 ...
- [FBA]SharePoint 2013自定义Providers在基于表单的身份验证(Forms-Based-Authentication)中的应用
//http://tech.ddvip.com/2014-05/1401197453210723.html 由于项目的需要,登录SharePoint Application的用户将从一个统一平台中获取 ...
- SharePoint 2013自定义Providers在基于表单的身份验证(Forms-Based-Authentication)中的应用
由于项目的需要,登录SharePoint Application的用户将从一个统一平台中获取,而不是从Domain中获取,所以需要对SharePoint Application的身份验证(Claims ...
- SharePoint 2013 母版页修改后,无法添加应用程序
原文:SharePoint 2013 母版页修改后,无法添加应用程序 问题描述:前一段时间尝试了一下将HTML文件转换为母版页,但是,用着用着又发现新的问题,我们转换的母版页,设置成默认母版页以后,无 ...
- sharepoint 2013 自定义列表eventhandle权限控制
记录一下如何在sharepoint server 2013自定义列表中,使用eventhandle控制自定义列表custom list的条目item权限. ///<summary> /// ...
- SharePoint开发 - 自定义导航菜单(一)菜单声明与配置
博客地址 http://blog.csdn.net/foxdave 本篇描述自定义sharepoint菜单的一种方式,自定义菜单适用于一些门户等需求的网站 自定义的菜单有自己的数据源,可以是数据表,可 ...
随机推荐
- IOS中十六进制的颜色转换为UIColor
IOS中十六进制的颜色转换为UIColor #pragma mark - 颜色转换 IOS中十六进制的颜色转换为UIColor + (UIColor *) colorWithHexString: (N ...
- 关于学习YYKit的记录
<1>遇到的问题 <1>使用@[].mutableCopy创建可变数组 代码出处:YYKitDemo-> YYRootViewController 源代码:self.ti ...
- GCD中的dispatch_group函数的详解
<一>引入dispatch_group函数的目的 在追加到dispatch_Queue中的多个处理全部结束后想要执行结束的处理,这种需求经常会在我们的程序中出现 (第一种情况)只使用一个S ...
- UEditor无法复制的解决方法
今天终于知道UEditor不能复制的真正原因啦,还是自己一直没有仔细研究. UEditor 粘贴 Excell 中的表格时报错导致无法粘贴的解决办法 在UEditor一些版本中,如果粘贴Excell中 ...
- mysql中数据类型的取值范围
mysql整型bigint.int.mediumint.smallint 和 tinyint的语法介绍,如下: 1.bigint 从 -2^63 (-9223372036854775808) 到 2^ ...
- HTML <fieldset> 标签
<div style="height:360px;width:180"> <fieldset> <legend> 用户管理 </legen ...
- C# Excel导入导出
/// <summary> /// 导出Excel /// </summary> /// <typeparam name="T"></ty ...
- 利用webview实现在andorid中嵌入swf
项目背景是这样的,一套系统有三个客户端分别是网页,flex和android,现在已经在flex上面做好了一个在线客户视频聊天系统,然后在这个基础上修改打包成了SWF,放在网页上面使用效果不错,但是利用 ...
- C#调用自定义表类型参数
-SQL SERVER生成测试环境: --创建测试DB CREATE database Sales; go USE Sales GO --创建表类型 IF TYPE_ID('LocalDT') IS ...
- 【零基础学习iOS开发】【转载】
原文地址:http://www.cnblogs.com/mjios/archive/2013/04/24/3039357.html 本文目录 一.什么是iOS 二.主流手机操作系统 三.什么是iOS开 ...