加入功能区button到SP2010某一列表或库

        有时候你须要给列表/库的功能区加入新button--没有什么比这更简单的了。

你仅仅须要新建一个SP项目。加入一个feature,加入一个空白元素。编辑它的Elements.xml文件。

        大多说时候它看起来像这样:
        Elements.xml:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <CustomAction
Id="{41C23DD2-6FEB-4636-AE4F-41B8E2A2D415}"
<strong> RegistrationId="100"</strong>
<strong> RegistrationType="List"</strong>
Location="CommandUI.Ribbon"
Sequence="5"
Title="Custom Lists Button"> <CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.List.Settings.Controls._children">
<Button
Id="{09A51440-C3A6-4103-874A-383747042E75}"
Alt="Custom Lists Button"
Sequence="5"
Command="{42844423-382B-4e87-BEC4-34B0601DA98F}"
Image32by32="/_layouts/images/menulistsettings.gif"
Image16by16="/_layouts/images/itdcl.gif"
LabelText="Custom Lists Button"
TemplateAlias="o1" />
</CommandUIDefinition>
</CommandUIDefinitions> <CommandUIHandlers>
<CommandUIHandler
Command="{42844423-382B-4e87-BEC4-34B0601DA98F}"
EnabledScript=""
CommandAction="javascript: alert('Custom Lists Button!');" />
</CommandUIHandlers> </CommandUIExtension>
</CustomAction>
</Elements>

部署解决方式。激活feature结果是:



        这种方法的缺点是button会出如今每一个现有自己定义列表中,就算你新建自己定义列表也会出现。

原因是RegistrationId="100"。这里100是自己定义列表的类型。

假设要给某个列表实例提供button的话。你能够使用一下方法:

创建列表定义并分配RegistrationId到列表定义的Type

        首先须要新创建列表定义:

        打开列表定义的Elements.xml。复制Type值:

        粘贴该值到button的Elements.xml中RegistrationId:
<CustomAction
Id="{67A1EB46-A49B-4aff-B456-068909C39599}"
RegistrationId="10000"
RegistrationType="List"
Location="CommandUI.Ribbon"
Sequence="5"
Title="List Definition Button"> <CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.List.Settings.Controls._children">
<Button
Id="{3F083F8B-95D6-436b-A130-3EF1E8C04E3C}"
Alt="List Definition Button"
Sequence="5"
Command="{AF90D558-00DA-4ccf-B4F4-169CD9162CD0}"
Image32by32="/_layouts/images/menulistsettings.gif"
Image16by16="/_layouts/images/itdcl.gif"
LabelText="List Definition Button"
TemplateAlias="o1" />
</CommandUIDefinition>
</CommandUIDefinitions> <CommandUIHandlers>
<CommandUIHandler
Command="{AF90D558-00DA-4ccf-B4F4-169CD9162CD0}"
EnabledScript=""
CommandAction="javascript: alert('List Definition Button!');" />
</CommandUIHandlers> </CommandUIExtension>
</CustomAction>

最后,加入列表定义到feature,这样它能随着解决方式一起部署:

        激活feature后,你应该能够给予新建列表定义创建新的列表:


        当你从定义创建列表时,你应该能看到button:

        另外,为了阻止用户使用新列表定义创建列表。你能够将定义设置为隐藏(这样用户看不到),然后你能够在FeatureActivated方法的feature event receiver中创建列表实例。

用程序加入button

        加入一个event receiver到feature:

        加入例如以下代码到FeatureActivated方法中:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
//Depending from the feature scope - can be SPSite
var web = properties.Feature.Parent as SPWeb; //Get list instance - here You can also create a new list
var list = web.Lists.TryGetList("RibbonButtonList"); if (list != null)
{
//Add new user custom action to the list
var userAction = list.UserCustomActions.Add();
//Set action's location
userAction.Location = "CommandUI.Ribbon";
//This one is Optional as we are adding the same later
userAction.ImageUrl = "/_layouts/images/menulistsettings.gif";
//Command body
userAction.CommandUIExtension = @"<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location=""Ribbon.List.Settings.Controls._children"">
<Button
Id=""{5557CC45-324E-41bb-9E88-A535DBF1BF6B}""
Alt=""Programmatically Added Button""
Sequence=""5""
Command=""{234F6E9E-80A3-4f70-9683-02067515801E}""
Image32by32=""/_layouts/images/menulistsettings.gif""
Image16by16=""/_layouts/images/itdcl.gif""
LabelText=""Programmatically Added Button""
TemplateAlias=""o1"" />
</CommandUIDefinition>
</CommandUIDefinitions> <CommandUIHandlers>
<CommandUIHandler
Command=""{234F6E9E-80A3-4f70-9683-02067515801E}""
EnabledScript=""""
CommandAction=""javascript: alert('Programmatically Added Button!');"" />
</CommandUIHandlers> </CommandUIExtension>"; userAction.Update();
}
}

部署解决方式时要确保我们要加入button的列表已经存在并激活feature。你应该能在列表功能区看到新button:



        这就是所有了,如今你应该能够通过以上方法加入功能区button到一个列表了吧。

加入功能区buttonRibbon Button到SP2010特定列表或库的更多相关文章

  1. sharepoint 2013 列表和库标签 元数据导航配置(2)

    接前面提到的,如何创建一个术语库.sharepoint 2013 列表和库标签 元数据导航配置(1), 现在要做的,就是如何在自定义或者文档库中使用这个术语库,实现标签功能,通过这些标签,找到对应的文 ...

  2. 跟我学SharePoint 2013视频培训课程——排序、过滤在列表、库中的使用(10)

    课程简介 第10天,SharePoint 2013排序.过滤在列表.库中的使用. 视频 SharePoint 2013 交流群 41032413

  3. 跟我学SharePoint 2013视频培训课程——探索默认的列表和库(6)

    课程简介 第6天,探索默认的列表和库. 视频 SharePoint 2013 交流群 41032413

  4. [Beginning SharePoint Designer 2010]列表和库&内部内容类型

    本章概要: 1.SPS如何组织管理数据 2.如何创建列表和文档库 3.如何使用视图来过滤分类,分组列表和库 4.如何创建内容类型来应用一个定义好的结构到数据和文档中

  5. OSS.Common获取枚举字典列表标准库支持

    上篇(.Net Standard扩展支持实例分享)介绍了OSS.Common的标准库支持扩展,也列举了可能遇到问题的解决方案.由于时间有限,同时.net standard暂时还没有提供对Descrip ...

  6. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q121-Q123)

    Question  121 You are designing a SharePoint 2010 workflow that will be used to monitor invoices. Th ...

  7. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q1-Q3)

    这里我把从网上搜集到的针对Sharepoint 70-576的有关练习进行系统的解析,整理成一个系列, 分期.分批次共享出来,供大家研究. 70-573考试注重的是"知道"相关知识 ...

  8. 自定义和扩展 SharePoint 2010 Server 功能区

    了解构成 SharePoint 2010 服务器功能区的组件以及如何通过演练两个功能区自定义项方案来自定义功能区. 适用范围: Microsoft SharePoint Foundation 2010 ...

  9. SharePoint 2013无代码实现列表视图的时间段动态筛选

    本文介绍两种为列表视图设置时间段筛选器的方法.其中,第一个方法用于SharePoint Server,第二个方法同时还能用于SharePoint Foundation. 方法一:日期筛选器Web部件 ...

随机推荐

  1. vim calendar插件配置

    近日学习markdown,试着记个日志,安装了vim的知名插件calendar:https://github.com/mattn/calendar-vim. 使用网上配置,发现回车之后日期是昨天的,于 ...

  2. Google的兼容包问题【转】

    转自:http://blog.sina.com.cn/s/blog_3e28c8a50101g14g.html 项目之前好好的,今天开Eclipse,,出错. 错误Error retrieving p ...

  3. egret-android-support-gradle版

    从3.1.3开始,Egret已经实现了Gradle构建!所以下文你爱看不看! 迟钝的Egret从3.1.3版本才开始支持Gradle,而笔者早在1.6.x版本就已经支持了,说明什么?说明Egret在某 ...

  4. centos 6.5安装GitLab全过程和问题记录

    GitLab,是一个使用 Ruby on Rails 开发的开源应用程序,与Github类似,能够浏览源代码,管理缺陷和注释,非常适合在团队内部使用. 官方只提供了Debian/Ubuntu系统下的安 ...

  5. 普林斯顿大学算法课 Algorithm Part I Week 3 比较器 Comparators

    比较器接口(Comparator interface):用可选顺序(alternate order)进行排序 public interface Comparator<key> int co ...

  6. C#格式化成小数

    datagridview某列格式化成两位小数 ............................................................................. ...

  7. 业务需求那些事,使用WCF如何实现业务需求!

    最近遇到一个新项目,需要与硬件结合,进行读取信息并保存在数据库中.业务要求也在昨天发布一个问题,当然感谢许多园内的朋友出谋划策,截图有真相! 关于这个问题,我做了如下假设.目前处于测试状态,代码比较简 ...

  8. SqlServer2008 数据库同步的两种方式(Sql JOB)

    尊重原著作:本文转载自http://www.cnblogs.com/tyb1222/archive/2011/05/27/2060075.html 数据库同步是一种比较常用的功能.下面介绍的就是数据库 ...

  9. root cause:org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException

    今天在调试SSH与Ajax时,服务器端报出JSON异常:

  10. 20151203--filter

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/htm ...