Pet*_*lke 7 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>
Run Code Online (Sandbox Code Playgroud)
工作实例

完整的Visual Studio解决方案:http: //employees.claritycon.com/pwalke/blogs/working.zip
Elements XML:我从上面的代码改变了2行.
第28行:将按钮与下面压缩代码的列表模板中指定的自定义产品列表ID 10001相关联.
RegistrationId="10001"
Run Code Online (Sandbox Code Playgroud)
第85行:告诉SharePoint将项目放在"项目"菜单中.
<CommandUIDefinition Location="Ribbon.ListItem.New.Controls._children">
Run Code Online (Sandbox Code Playgroud)
屏幕截图 - 我原本期望将自定义功能区按钮添加到New Item的左侧.

完整的Visual Studio解决方案:http: //employees.claritycon.com/pwalke/blogs/notworking.zip
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>
Run Code Online (Sandbox Code Playgroud)
结果是:

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

最后结果
实际上,你的列表定义出了问题.我没有足够的时间来检查所有的xml,所以我只是创建了新的列表,其列表与我上面描述的相同,删除了旧列表,现在一切正常.您可以使用以下链接下载最终解决方案:
https://sites.google.com/site/omlinfiles/StackOverflow.RibbonCustomList.zip?attredirects=0&d=1
PS不要忘记更改网站URL
我能够解决这个问题。感谢 omlin 帮助我完成了这一任务。
这是一个由两部分组成的问题。
1:按照omlin的建议,我改变了
Ribbon.Items.New.Controls._children
Run Code Online (Sandbox Code Playgroud)
到
Ribbon.ListItem.New.Controls._children
Run Code Online (Sandbox Code Playgroud)
2:我必须更改 schema.xml 的工具栏声明
<ToolBar />
Run Code Online (Sandbox Code Playgroud)
到
<Toolbar Type="Regular"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12265 次 |
| 最近记录: |