您如何将事件接收器绑定到*特定* 自定义内容类型? [英] How do you bound an event receiver to a *specific* custom content type?

查看:21
本文介绍了您如何将事件接收器绑定到*特定* 自定义内容类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个事件接收器并添加到 GAC.

I've created an event receiver and have added to the GAC.

如何将事件接收器绑定到特定自定义内容类型?

How do I bound an event receiver to a specific custom content type?

我需要从 XML 文件执行此操作:

I need to do this from an XML file:

到目前为止我有:

指向 Elements.xml 文件但不确定 Elements.xml 文件的 Feature.xml.

Feature.xml that points to an Elements.xml file but am not sure about the Elements.xml file.

您如何引用特定的内容类型?(我有特定内容类型的指南)

How do you reference a specific content type? (I have the guid for the specific content-type)

推荐答案

要将事件接收器绑定到特定的内容类型,请使用内容类型元素文件的 XmlDocuments 元素.以下是我即将出版的书构建 SharePoint 用户体验" 中的一段相当独家的摘录:

To bind an event receiver to a specific content type, you use the XmlDocuments element of the content type elements file. Here's a rather exclusive excerpt from my upcoming book "Building the SharePoint User Experience":

而且,为了澄清一下,由于我没有看到您尝试发布的 XML,您可以将其添加到 elements.xml 文件中的内容类型声明中.

And, just to clarify, since I don't see the XML you tried to post, you would add this to the content type declaration in the elements.xml file.

(...)

使用功能将事件接收器附加到内容类型

像我们刚刚看到的那样附加事件接收器的重要一点是要注意,无法将接收器绑定到内容类型,只能绑定到列表模板.

The important thing with attaching event receivers like we just saw is to notice that there is no way to bind a receiver to a content type, only to a list template.

不,也无法将接收器添加到单个列表中.但是,正如我们在列表森林章节的电子邮件启用自定义列表部分中看到的,我们可以使用代码以编程方式添加事件接收器.我们也可以使用相同的技术将事件接收器添加到内容类型,但应该有一种方法可以在功能中使用 CAML 来做到这一点.毕竟这是我们定义内容类型的地方,我们将在本章后面看到.

No, there are no ways to add receivers to individual lists either. However, as we saw in the Email enabling custom lists section in the Forest of lists chapter we can programmatically add event receivers using code. We can use the same technique to add event receivers to a content type as well, but there should be a way to do this using CAML in a feature. After all that is where we define the content type, as we will see later in the chapter.

答案?内容类型中的事件接收器在元素文件的不同部分中定义.我们再次查看 XmlDocuments 和第三个内置 XmlDocument 类型 Receiver.Receiver XmlDocument 位于 http://schemas.microsoft.com/sharepoint/events 命名空间中.如果要在默认 SharePoint 安装中查看 Receiver XmlDocument,请在 ctypeswss.xml 文件中搜索内容类型为 0x010107 的 DocumentWorkflowItem:

The answer? Event receivers in content types are defined in a different section of the elements file. Again we look to XmlDocuments and the third built-in XmlDocument type Receiver. The Receiver XmlDocument resides in the http://schemas.microsoft.com/sharepoint/events namespace. If you want to see a Receiver XmlDocument in your default SharePoint installation, search the ctypeswss.xml file for the content type 0x010107, the DocumentWorkflowItem:

<XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/events">
 <spe:Receivers xmlns:spe="http://schemas.microsoft.com/sharepoint/events">
  <Receiver>
   <Name>Workflow Library Item Added</Name>
   <Type>ItemAdded</Type>
   <SequenceNumber>1</SequenceNumber>
   <Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral,~CCC
    PublicKeyToken=71e9bce111e9429c</Assembly>
   <Class>Microsoft.SharePoint.Workflow.SPWorkflowLibraryEventReceiver</Class>
   <Data />
   <Filter />
  </Receiver>
… (snipped for space saving purposes
 </Receivers>
</XmlDocument>

注意该示例使用前缀 spe: 作为 Receivers 元素.从技术角度来看,这不是必需的,但可以增加代码的清晰度.如您所见,Receiver 元素遵循元素中定义的常规项目事件接收器的结构.当然,除了在内容类型的 XmlDocument 部分中定义的接收器.

Note The example uses a prefix spe: for the Receivers element. This is not necessary from a technical point of view, but can add clarity to your code. As you can see, the Receiver element follows the structure of a regular item event receiver as defined in elements. Except, of course, that the receiver is defined in the XmlDocument section of the content type.

这篇关于您如何将事件接收器绑定到*特定* 自定义内容类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆