标签:
你仅仅须要新建一个SP项目。加入一个feature,加入一个空白元素。编辑它的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结果是:
原因是RegistrationId="100"。这里100是自己定义列表的类型。
假设要给某个列表实例提供button的话。你能够使用一下方法:
<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,这样它能随着解决方式一起部署:
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:
加入功能区buttonRibbon Button到SP2010特定列表或库
标签:
原文地址:http://www.cnblogs.com/lcchuguo/p/5204071.html