惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Commits to openclaw:main
Recent Commits to openclaw:main
Simon Willison's Weblog
Simon Willison's Weblog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Schneier on Security
Cyberwarzone
Cyberwarzone
NISL@THU
NISL@THU
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
The Hacker News
The Hacker News
Schneier on Security
Schneier on Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Help Net Security
Help Net Security
Scott Helme
Scott Helme
SecWiki News
SecWiki News
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
L
LINUX DO - 最新话题
L
Lohrmann on Cybersecurity
TaoSecurity Blog
TaoSecurity Blog
K
Kaspersky official blog
Attack and Defense Labs
Attack and Defense Labs
P
Privacy & Cybersecurity Law Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
L
LINUX DO - 热门话题
N
News and Events Feed by Topic
Know Your Adversary
Know Your Adversary
Forbes - Security
Forbes - Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Google DeepMind News
Google DeepMind News
T
Tor Project blog
P
Palo Alto Networks Blog
Cisco Talos Blog
Cisco Talos Blog
A
Arctic Wolf
O
OpenAI News
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
AI
AI
N
News and Events Feed by Topic
博客园 - Franky
T
Threatpost
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Engineering at Meta
Engineering at Meta
S
SegmentFault 最新的问题
C
Cyber Attacks, Cyber Crime and Cyber Security
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
B
Blog RSS Feed
Hacker News: Ask HN
Hacker News: Ask HN
D
Docker
博客园 - 三生石上(FineUI控件)

博客园 - Sunmoonfire

SharePoint 2013无代码实现列表视图的时间段动态筛选 SharePoint Foundation 2013 with SP1 在SharePoint列表中使用自增栏 SharePoint 2010自定义母版页小技巧——JavaScript和CSS引用 修改SharePoint列表项显示“新”图标的天数 通过PowerShell实现SharePoint列表增删改 在SharePoint 2010页面中嵌入SWF文件 在LINQ to SharePoint中使用创建时间,创建者,修改时间,修改者 SharePoint 2010之LINQ与SPMetal 修改SharePoint页面上的控件数量的限制 SharePoint 2010:部署.resx(资源)文件到App_GlobalResources的简单方法 在SharePoint 2010中使用jQuery 在SharePoint 2010环境下区分w3wp进程 打SharePoint 2010 SP1后访问用户配置文件同步服务应用程序出错的解决办法 使用[本人]创建视图筛选时的一个问题和解答 "缺少服务器端相关性"的内容定位 SharePoint 2010开发工具图解系列:Visual Studio 2010创建事件接收器 SharePoint 2010开发工具图解系列:Visual Studio 2010创建列表 SharePoint 2010开发工具图解系列:Visual Studio 2010 SharePoint Tool入门
SharePoint 2013:自定义ECB菜单项的添加
Sunmoonfire · 2014-07-31 · via 博客园 - Sunmoonfire

本文分别介绍了两种常用的添加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 > 0)
                    {
                        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 = 106;
                    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 > 0)
                    {
                        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