无法将功能区按钮添加到自定义列表

时间:2010-09-15 18:50:55

标签: sharepoint sharepoint-2010

编辑:使用来自Omlin的输入更新

我正在尝试向功能区添加自定义按钮。我想要与名为“Products”的自定义列表关联的按钮。我可以获取显示内置列表的按钮,例如共享文档,但不能显示自定义产品列表。

下面是我的代码使用现有列表而不使用自定义列表的示例。我还附加了创建自定义列表和功能区按钮的工作和非工作代码的链接。这些解决方案假设您在http://intranet.contoso.com创建了一个站点。您可能需要更改项目的站点URL以获取要运行的代码。


使用和内置列表(共享文档):

元素XML:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
       <CustomAction
              Id="CustomRibbonTab"
              Location="CommandUI.Ribbon.ListView"
              RegistrationId="101"
              RegistrationType="List"
              Title="My Custom UI"
              Sequence="5"
              >
              <CommandUIExtension>
                     <CommandUIDefinitions>
                           <CommandUIDefinition Location="Ribbon.Documents.New.Controls._children">
                                  <Button
                                         Id="Ribbon.Items.New.RibbonTest"
                                         Alt="Test Button"
                                         Sequence="5"
                                         Command="Test_Button"
                                         LabelText="Click me!"
                                         Image32by32="/_layouts/images/ribbon_blog_32.png"
                                         Image16by16="/_layouts/images/ribbon_blog_16.png"
                                         TemplateAlias="o1"
                                         />
                           </CommandUIDefinition>
                     </CommandUIDefinitions>
                     <CommandUIHandlers>
                           <CommandUIHandler Command="Test_Button"
                                                         CommandAction="javascript:alert('I am a test!');">

                           </CommandUIHandler>
                     </CommandUIHandlers>
              </CommandUIExtension>
       </CustomAction>
</Elements>

工作示例 Working Example

完整的Visual Studio解决方案http://employees.claritycon.com/pwalke/blogs/working.zip


不工作

元素XML :我从上面的代码中更改了2行 第28行:将按钮与下面压缩代码的列表模板中指定的自定义产品列表ID 10001相关联。

RegistrationId="10001"

第85行:告诉SharePoint将项目放在“项目”菜单中。

<CommandUIDefinition Location="Ribbon.ListItem.New.Controls._children">

屏幕截图 - 我原本希望将自定义功能区按钮添加到新项目的左侧。 Not Working

完整的Visual Studio解决方案http://employees.claritycon.com/pwalke/blogs/notworking.zip

3 个答案:

答案 0 :(得分:7)

  

Ribbon.Items.New.Controls._children

根据MSDN,根本没有这样的Ribbon位置:)

我现在没有SharePoint进行测试,但我觉得你需要使用 Ribbon.ListItem.New.Controls._children


更新:到目前为止,我测试了添加到Ribbon.ListItem.New.Controls._children的按钮。它适用于我(我还没有使用任何注册类型和注册ID)。我使用的示例代码是:

  <CustomAction
  Id="ChangeBrowseTabTitle"
  Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.ListItem.New.Controls._children">
          <Button
            Id="Ribbon.ListItem.New.RibbonTest"
            Alt="Test Button"
            Sequence="5"
            Command="Test_Button"
            LabelText="Click me!"
            Image32by32="/_layouts/SharePointTestProject/avatar32.png"
            TemplateAlias="o1"
              />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler Command="Test_Button" CommandAction="javascript:alert('I am a test!');" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>

结果是:

alt text

所以我现在将尝试测试自定义列表。


更新:我接受了你的“notworking.zip”项目,并尝试了代码。没有运气。 但是,当我创建空白的新列表定义(解决方案 - &gt;右键单击 - &gt;添加 - &gt;新项目 - &gt;内容类型的列表定义)时,为其分配了自定义ID(10012),并在功能区中更改了引用,它开始工作了:

alt text


最终结果

实际上你的列表定义出了问题。我没有足够的时间来检查所有的xml,所以我只是创建了新的列表,其中包含了我上面描述的相同列,删除了旧列表,现在一切正常。您可以使用以下链接下载最终解决方案:

https://sites.google.com/site/omlinfiles/StackOverflow.RibbonCustomList.zip?attredirects=0&d=1

P.S。不要忘记更改网站网址

答案 1 :(得分:2)

如果您想在自定义列表中添加功能区按钮,这是通过网站操作菜单界面创建的,而不是vs2010上的功能,您可以将属性RegistrationId设置为 100 (通用列表) )。

示例:

    <?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Id="ListFolderSecurityButton"
    RegistrationType="List"
    RegistrationId="100"
    Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
         Location="Ribbon.ListItem.New.Controls._children">
          <Button
           Id="Ribbon.ListItem.New.Controls.ListFolderSecurity"
           Alt="Gestiona los permisos de acceso de lectores en el folder"
           Sequence="10"
           Image32by32="/_layouts/images/Permissions32.png"
           Command="ManageSecurityFolder"
           LabelText="Folder Permissions"
           TemplateAlias="o2"/>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
         Command="ManageSecurityFolder"
         CommandAction="/CustomPages/PMS_AdminSecurityFolder.aspx" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
  <!--<HideCustomAction Id="Ribbon.ListItem.New.Controls.ListFolderSecurityButton" Location="Ribbon.ListItem.New.Controls._children">
  </HideCustomAction>-->
</Elements>

答案 2 :(得分:0)

我能够解决这个问题。感谢omlin让我成为那里的一部分。

这是一个由两部分组成的问题。

1:  正如omlin所说,我改变了

Ribbon.Items.New.Controls._children 

Ribbon.ListItem.New.Controls._children

2:我必须从

更改schema.xml的工具栏声明
<ToolBar />

<Toolbar Type="Regular"/>