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

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

问题描述

我已经创建了一个事件接收器,并已添加到GAC中。



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



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



到目前为止,我有: p>

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



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

解决方案

要将事件接收器绑定到特定的内容类型,请使用内容类型元素文件的XmlDocuments元素。以下是我即将发布的书籍构建SharePoint用户体验的相当独特的摘录:



只是为了澄清,因为我没有看到你试图发布的XML,所以你可以将它添加到elements.xml文件中的内容类型声明。



(...)



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



我们刚刚看到附加事件接收器的重要事情是注意到没有办法将接收者绑定到内容类型,只能绑定到列表模板。



不,没有办法将接收者添加到单个列表中。但是,正如我们在列出林一章的电子邮件启用自定义列表部分中所看到的,我们可以使用代码以编程方式添加事件接收器。我们可以使用相同的技术将事件接收器添加到内容类型,但是应该有一种方法可以在功能中使用CAML。所有这些都是我们定义内容类型的地方,我们将在本章后面看到。



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

 < XmlDocument NamespaceURI =http://schemas.microsoft.com/sharepoint/events> 
< spe:Receivers xmlns:spe =http://schemas.microsoft.com/sharepoint/events>
<接收者>
< Name>工作流程库项目已添加< / 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>
...(节省空间用于
< / Receivers>
< / XmlDocument>

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


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?

I need to do this from an XML file:

So far I have:

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)

解决方案

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":

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.

(...)

Attaching event receivers to content types using features

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.

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.

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>

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天全站免登陆