Event receiver attached to content type via XmlDocuments ignored?

Michael Stum
  • Event receiver attached to content type via XmlDocuments ignored? Michael Stum

    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?

  • 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.

  • 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.

Tags
content-type event-handlers
Related questions and answers
  • ="{CE8F7528-E643-4473-94E0-BAA57BD2F6E6}" Name="TeamName" StaticName="TeamName" DisplayName="Team Name" Type="Text"&gt; &lt;/Field>; &lt;Field ID="{E508D1FA-D3A5-4e91-828B-3BFB43D4F7C5}" Name... ID="0x0100B4366B5F6383463b8464DBD2EDD5E097" Name="Withdrawal" Description="Record of a team withdrawal" Hidden="False"&gt; &lt;FieldRefs> &lt;FieldRef ID... xmlns:ows="Microsoft SharePoint" Title="Withdrawals" FolderCreation="FALSE" Direction="LTR" Url="Lists/Withdrawals" EnableContentTypes="TRUE" BaseType="0"&gt; &lt;MetaData> &lt;ContentTypes>

  • " /&gt; &lt;/ElementManifests> &lt;/Feature> elements.xml &lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;Elements xmlns="http://schemas.microsoft.com/sharepoint/"&gt; &lt;/Elements>... in a WebPart zone. When doing this, I get an error message : Tooltips: List View Web Part could not be added, list may be hidden. What's wrong with the list? feature.xml &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Feature Id="70d49f3d-233a-482d-97e3-dcec2c236171" Title="MyApp - Tooltips" Description="Creates a Tooltips list which can be used for mouse-over texts

  • ;DataSources> &lt;SharePoint:SPDataSource runat="server" DataSourceMode="ListItem" UseInternalName="true" selectcommand="&lt;View&gt;&lt;ViewFields&gt;&lt;FieldRef Name...;xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http...']").click(function(){ $("input[type=checkbox]").attr("checked", true); }); This changes the form field succesfully but does not save to the list when the form submits. I have also tried to call

  • the 'ListForm' it works. So I'm thinking that I've done something wrong in the content type definition. Here is the code: &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Elements xmlns="http://schemas.microsoft.com/sharepoint/"&gt; &lt;Field ID="{9381E2BE-CE62-4673-9C0D-8A7E4B087B55}" Name="MyPal" DisplayName="My Pal" Type="Text" /&gt; &lt;!-- Parent ContentType: Item (0x01) --&gt; &lt..." Inherits="TRUE" Version="0"&gt; &lt;FieldRefs> &lt;FieldRef ID="{9381E2BE-CE62-4673-9C0D-8A7E4B087B55}" Name="MyPal" DisplayName="My Pal" /&gt; &lt

  • Has anybody upgraded an old custom field type to use the new XSL transform in SharePoint 2010? I have a multi-column field type, and want the Display pattern to render the 2nd "column", which...;/RenderPattern> In WSS 3.0, this would render the 2nd column in the field as a hyperlink in the LVWP, which is what I want. In SharePoint 2010, I tried adding TRUE to my field type definition...="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal"&gt; &lt;xsl:template match="FieldRef[@FieldType='DataLinkUrl']" mode="Note_body"&gt; &lt;xsl:param name="thisNode" select="."/&gt; &lt;xsl

  • in-browser and they are visible in SPDesigner, but when I "View All Site Content" they are not there. Why is this the case? The Feature's Elements File: &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Elements Id="9e85eb79-6d8d-4ff3-b0d4-64d55c3bb577" xmlns="http://schemas.microsoft.com/sharepoint/"&gt; &lt;Module Name="Pages" Url="Pages"&gt; &lt;File Path="Example.aspx" Url="Example.aspx" IgnoreIfAlreadyExists="False"&gt; &lt;Property Name="Title" Value="The Example" /&gt; &lt;Property Name="ContentType" Value="Page" /&gt; &lt;/File> &lt

  • ()); } UPDATE: Based on feedback from Wictor, I tried the following: &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;webParts> &lt;webPart xmlns="http://schemas.microsoft.com/WebPart/v3"&gt; &lt.../WebPart/v2/ContentEditor\" /&gt; &lt;PartStorage xmlns=\"http://schemas.microsoft.com/WebPart/v2/ContentEditor\" /&gt;&lt;/WebPart>"; var webPartXml = "&lt;?xml version=\"1.0\" encoding=\"utf-8...;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;"; //webPartXml = webPartXml + "&lt;WebPart xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns

  • ;?xml version="1.0" encoding="utf-8" ?&gt; &lt;Elements xmlns="http://schemas.microsoft.com/sharepoint/"&gt; &lt;Module Name="WebPartPopulation" Url="_catalogs/wp" RootWebOnly="TRUE"&gt...; } } } } finally { if (site != null) site.Dispose(); } } In the feature.xml i have this below &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Feature Id="5d910db3-5adf-4f8e-a102-05d5a1653c59" Title="FeatureWithReceiver" Description="Description for FeatureWithReceiver" Version="12.0.0.0" Hidden="FALSE

  • what's actually happening. Here is the complete elements.xml I'm using: &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Elements xmlns="http://schemas.microsoft.com/sharepoint/"&gt; &lt;!-- High Importance --&gt; &lt;Field ID="{5FFCA09E-EF49-11DE-96C7-B58E56D89593}" Name="HighImportance" Group="AA Site Columns" DisplayName="High Importance" Type="Boolean"&gt; &lt;Default>0&lt;/Default> &lt;/Field>; &lt;!-- Show On Home --&gt; &lt;Field ID="{A8A659D4-42DC-409f-817F-A97DFC5694E6}" Name="ShowOnHome" Group="AA Site Columns" DisplayName="Display on Home" Type

Data information