Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a content type defined in Elements.xml and I want to add an Event Receiver. My Elements.xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <!-- Parent ContentType: Announcement (0x0104) -->
  <ContentType ID="0x0104008a424de98660457481eb7d8ddb5161ee"
               Name="News Posting"
               Group="News"
               Description="$Resources:NewsCTypeDescription"
               Inherits="TRUE"
               Version="1"
               Sealed="TRUE"
               >
    <FieldRefs>
      <FieldRef ID="{7EBC5918-CB79-440A-8DF3-480C6951C4EB}" Name="NewsExcerpt"/>
    </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>
            <Class>MyAssembly.NewsItemEventReceiver</Class>
            <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
            <SequenceNumber>10000</SequenceNumber>
            <Synchronization>Synchronous</Synchronization>
            <Data />
            <Filter />
          </Receiver>
        </spe:Receivers>
      </XmlDocument>
    </XmlDocuments>
  </ContentType>
</Elements>

The weird thing is that the Event Receiver never executes. I've checked the Schema with SharePoint Manager 2010, and it seems that the XmlDocuments element is ignored completely? Here's the content type SchemaXml according to SharePoint Manager:

<?xml version="1.0" encoding="utf-16"?>
<ContentType ID="0x0104008A424DE98660457481EB7D8DDB5161EE" Name="News Posting" Group="News" Description="A News Posting" Sealed="TRUE" Version="1">
  <Folder TargetName="_cts/News Posting" />
  <Fields>
    <Field ID="{c042a256-787d-4a6f-8a8a-cf6ab767f12d}" Name="ContentType" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="ContentType" Group="_Hidden" Type="Computed" DisplayName="Content Type" Sealed="TRUE" Sortable="FALSE" RenderXMLUsingPattern="TRUE" PITarget="MicrosoftWindowsSharePointServices" PIAttribute="ContentTypeID" Customization="">
      <FieldRefs>
        <FieldRef ID="{03e45e84-1992-4d42-9116-26f756012634}" Name="ContentTypeId" />
      </FieldRefs>
      <DisplayPattern>
        <MapToContentType>
          <Column Name="ContentTypeId" />
        </MapToContentType>
      </DisplayPattern>
    </Field>
    <Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Title" Group="_Hidden" Type="Text" DisplayName="Title" Required="TRUE" FromBaseType="TRUE" Customization="" ShowInNewForm="TRUE" ShowInEditForm="TRUE" />
    <Field ID="{7662cd2c-f069-4dba-9e35-082cf976e170}" Name="Body" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Body" Group="_Hidden" Type="Note" RichText="TRUE" RichTextMode="FullHtml" IsolateStyles="TRUE" DisplayName="Body" Sortable="FALSE" NumLines="15" Customization="" />
    <Field ID="{6a09e75b-8d17-4698-94a8-371eda1af1ac}" Name="Expires" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Expires" Group="_Hidden" Type="DateTime" DisplayName="Expires" Format="DateOnly" Customization="" />
    <Field ID="{7EBC5918-CB79-440A-8DF3-480C6951C4EB}" Group="News" Name="NewsExcerpt" DisplayName="Excerpt of the Article" Description="165 Characters maximum" MaxLength="165" Type="Text" Customization="" />
    </Field>
  </Fields>
  <XmlDocuments>
    <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
      <FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
        <Display>ListForm</Display>
        <Edit>ListForm</Edit>
        <New>ListForm</New>
      </FormTemplates>
    </XmlDocument>
  </XmlDocuments>
</ContentType>

I have tried adding a FormTemplates XmlDocument as well, just to see if that works, but even this is ignored (I've changed the ListForm to ListForm2, but the SchemaXml is unchanged.

I've deleted the entire Web Application and Content Database to make sure there was nothing stale/stuck, but the result is still the same.

Is XmlDocuments deprecated in SharePoint 2010? What are the alternatives?

share|improve this question
add comment

2 Answers

From TechNet, the issue is that using Inherits="TRUE" in the content type definition will ignore XmlDocuments.

You must use Inherits="FALSE" and manually add the fields to be inherited.

share|improve this answer
add comment

I am not certain if you have tried this, but I use the guid of the eventreceiver class in my content type. If you look in the ItemEventReceiver.cs file, you should see a guid under the namespace. Also, that file should point to the contenttype id. It would look like this:

[TargetContentType("ContentTypeID HERE")]
[Guid("guid here")]

Then your xml file would look like this:

<XmlDocuments>      
  <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/events">
    <Receivers>
      <Receiver>
        <Name>ItemAdded</Name>
        <Type>ItemAdded</Type>
        <Class>Guid From Above</Class>
        <SequenceNumber>1</SequenceNumber>
      </Receiver>
    <Receivers>
  </XmlDocument>
</XmlDocuments>

This is how mine looks and it seems to work fine. I have to do an IISRESET if I add a new receiver, but it does work.

share|improve this answer
    
Yes, I tried that. TargetContentType is part of VSeWSS though, so it's not 2010 compatible. Omitting that attribute still doesn't work. –  Michael Stum Jul 2 '10 at 0:45
    
Duh, you are right and this is 2010! Did you look in the default content types xml file to see how it looks in there? In 2007 that was in 12\TEMPLATE\FEATURES\ctypes –  spevilgenius Jul 2 '10 at 12:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.