加入功能区buttonRibbon Button到SP2010特定列表或库
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了加入功能区buttonRibbon Button到SP2010特定列表或库相关的知识,希望对你有一定的参考价值。
加入功能区button到SP2010某一列表或库
有时候你须要给列表/库的功能区加入新button--没有什么比这更简单的了。
你仅仅须要新建一个SP项目。加入一个feature,加入一个空白元素。编辑它的Elements.xml文件。
大多说时候它看起来像这样:![技术分享](https://image.cha138.com/20200614/a2ae8dd9a009445ab2a3943980316701.jpg)
![技术分享](https://image.cha138.com/20200614/a2ae8dd9a009445ab2a3943980316701.jpg)
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结果是:
![技术分享](https://image.cha138.com/20200614/ba227cf203ba4a95b9e3bff5f69ab3ab.jpg)
这种方法的缺点是button会出如今每一个现有自己定义列表中,就算你新建自己定义列表也会出现。
原因是RegistrationId="100"。这里100是自己定义列表的类型。
假设要给某个列表实例提供button的话。你能够使用一下方法:
创建列表定义并分配RegistrationId到列表定义的Type
首先须要新创建列表定义:
![技术分享](https://image.cha138.com/20200614/f3f489bbb19b45fd899e913136832d29.jpg)
打开列表定义的Elements.xml。复制Type值:
![技术分享](https://image.cha138.com/20200614/8dd8c91f43ea4a9e9cf13c65a0ef2469.jpg)
粘贴该值到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,这样它能随着解决方式一起部署:
![技术分享](https://image.cha138.com/20200614/df6a4b624eb74a128c38d10bb54ea54c.jpg)
激活feature后,你应该能够给予新建列表定义创建新的列表:
![技术分享](https://image.cha138.com/20200614/597e92bc051a45a7bb666edf2b22a694.jpg)
当你从定义创建列表时,你应该能看到button:
![技术分享](https://image.cha138.com/20200614/ca319886064141b997a703d668866821.jpg)
另外,为了阻止用户使用新列表定义创建列表。你能够将定义设置为隐藏(这样用户看不到),然后你能够在FeatureActivated方法的feature event receiver中创建列表实例。
用程序加入button
加入一个event receiver到feature:
![技术分享](https://image.cha138.com/20200614/58b5cc78a8714c1db04ce0fc39a177f2.jpg)
加入例如以下代码到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:
![技术分享](https://image.cha138.com/20200614/14840169c9d3472990d23ce85ccdf955.jpg)
这就是所有了,如今你应该能够通过以上方法加入功能区button到一个列表了吧。
以上是关于加入功能区buttonRibbon Button到SP2010特定列表或库的主要内容,如果未能解决你的问题,请参考以下文章
如何更改android edittext的样式,在弹出软键盘页面上加入button
VC 对话框程序加入工具栏button图标及其buttontooltip