How to register an event handler declaratively by content type?

Hi. everyone.

I'd like to register an event handler declaretively by content type.

According to a paragraph of  this article, it seems to be possible, but i don't know how to do this.

 Declaratively by content type, for example, to register an event handler for all documents of a specific type. Within the XML for a content type definition, you can register event receivers.

I created two content type named ct_a, ct_b, and I derived them from document content type.

ct_a and ct_b had a event handler respectively and  were associated with a list named list_a.

What i want to know are how to associate a event hander with a content type

and how to activate them.

Thanks for in advance.

 



Answer this question

How to register an event handler declaratively by content type?

  • TechNoFear

    Jeon,

    This was very helpful, specially since we are provisioning our site using ONET.XML and it's the only way to bind the handlers.

    Thanks.


  • Mirricle

    This is the answer.

    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <ContentType ID="0x0100c07095261b4f48408d60ad8654b69d68" Name="DevelopingCT" Group="Development" Description="Developing Content Type" Version="0">
        <FieldRefs>
          <FieldRef ID="{0c177b88-bf35-4692-8456-cc14aaabecc0}" Name="DevelopingCTField" />
        </FieldRefs>
        <XmlDocuments>
          <XmlDocument NamespaceURI="
    http://schemas.microsoft.com/sharepoint/events">
            <spe:Receivers xmlns:spe="
    http://schemas.microsoft.com/sharepoint/events">
              <Receiver>
                <Name>ItemAdded</Name>
                <Type>ItemAdded</Type>
                <SequenceNumber>1</SequenceNumber>
                <Assembly>AssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=TokenNumber</Assembly>
                <Class>Namespace.ClassName</Class>
                <Data>
                </Data>
                <Filter>
                </Filter>
              </Receiver>
              <Receiver>
                <Name>ItemAdding</Name>
                <Type>ItemAdding</Type>
                <SequenceNumber>2</SequenceNumber>
                <Assembly>AssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=TokenNumber</Assembly>
                <Class>Namespace.ClassName</Class>
                <Data>
                </Data>
                <Filter>
                </Filter>
              </Receiver>          
            </spe:Receivers>
          </XmlDocument>
        </XmlDocuments>
      </ContentType>
    </Elements>


  • How to register an event handler declaratively by content type?