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-单项选择框
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
- OC NSDictionary
OC NSDictionary NSDictionary初始化 NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys:@ ...
- Sumlime Text编辑文件后快速刷新浏览器
作为Web开发人员,我们经常会这么做:在编辑器中调整代码,保存文件,切换到浏览器,然后刷新浏览器页面来查看结果.在代码编辑过程中,我们需要重复进行很多次这些操作. 如果你使用的是Sublime Tex ...
- ORACLE数据库异步IO介绍
异步IO概念 Linux 异步 I/O (AIO)是 Linux 内核中提供的一个增强的功能.它是Linux 2.6 版本内核的一个标准特性,当然我们在2.4 版本内核的补丁中也可以找到它.AIO 背 ...
- MySQL 调优基础(一) CPU与进程
一般而言,MySQL 的调优可以分为两个层面,一个是在MySQL层面上进行的调优,比如SQL改写,索引的添加,MySQL各种参数的配置:另一个层面是从操作系统的层面和硬件的层面来进行调优.操作系统的层 ...
- json字符串的拼接,并转换为json对象
<html> <head> <script> var qianzhui = "cc"; var test1=""; func ...
- windows开关机时间记录
1. 开机时间记录批处理文件,kai.bat @echo off echo %date% %time% 开机 >>D:\开关机记录\开关机时间.txt 2. 关机时间记录批处理文件,gua ...
- python脚本实现自动保留ctime最近的几个文件
使用了给字典排序的sorted方法 #!/usr/bin/env python # coding:utf-8 import os def rm_backup(rm_path,days): files_ ...
- (转)android.intent.action.MAIN与android.intent.category.LAUNCHER
android.intent.action.MAIN决定应用程序最先启动的Activity android.intent.category.LAUNCHER决定应用程序是否显示在程序列表里 在网上看到 ...
- 004.UDP--拼接UDP数据包,构造ip头和udp头通信(使用原始套接字)
一.大致流程: 建立一个client端,一个server端,自己构建IP头和UDP头,写入数据(hello,world!)后通过原始套接字(SOCK_RAW)将包发出去. server端收到数据后,打 ...