zoukankan      html  css  js  c++  java
  • 加入功能区buttonRibbon Button到SP2010特定列表或库

    加入功能区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到一个列表了吧。
  • 相关阅读:
    Element.scrollIntoView()
    dot.js
    微信小程序页面跳转导航wx.navigateTo和wx.redirectTo
    小程序swiper 滑块视图容器
    小程序表单提交
    自适应宽度圆角导航如何实现
    PC端和移动端一些奇葩兼容性问题
    如何实现两行内容增多和一行内容增多,多余的内容显示省略号
    表单提交判断,数据只能提交一次判断
    改变CSS世界纵横规则的writing-mode属性
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/5204071.html
Copyright © 2011-2022 走看看