views:

528

answers:

2

I have created an Item Event Receiver for a document library and I have test that the logic works correctly and it all does. The next thing I wanted to do is automatically create the list when a site is created so I added the list to the ONET.xml file for the site:

<Lists>
  <List Title="Documents" Description="Documents " url="MyDocumentLibrary" Type="10002" FeatureId="CFD8504D-70EB-4ba2-9CCB-52E38DB39E60" QuickLaunchUrl="Docs/AllItems.aspx" />
</Lists>

And I ensure that the feature for this list is also activated be adding the feature to the

<WebFeatures>
  <Feature ID="CFD8504D-70EB-4ba2-9CCB-52E38DB39E60" />
</WebFeatures>

The problem occurs after I create the site, when I add a document to the list the Item Event Receiver does not run. However if I manually for to the web site features and deactivate and then reactivate the feature the Item Event Receiver does run. It seems that when creating a list through the ONET.xml and activating the feature it does not bind the Item Event Receiver to the list. What is the work around for this? Is this a bug?

A: 

This is probably a problem with site provisioning order. Specifically, the web feature is being activated before the list exists.

Alex Angas
This was what I thought but thinking about how you would do this manually I thought that this didn't make sense. In the manual process I would have to activate the feature then add the list which is the same order site creation is meant to happen in.
Michael Edwards
A: 

In the code snippet i could see that you the Custom List Type Type="10002" in that case you can easily associate the Event Handler to the List using another feature that has the following item in the Element Manifest XML

<Elements xmlns="http://schemas.microsoft.com/sharepoint/"&gt;
<Receivers ListTemplateId="10002">   
 <Receiver>
  <Name>AddedEventHandler</Name>
  <Type>ItemAdded</Type>
  <SequenceNumber>10000</SequenceNumber>
  <Assembly>full assembkly</Assembly>
  <Class>Class of the event handler</Class>
  <Data></Data>
  <Filter></Filter>
 </Receiver>
</Receivers>

  1. Also note that the above feature needs to be Web Scoped
  2. All the List that are created based on the Type 10002 will have this EventHandler plugged to them
  3. I have been doing this and it works, No race condition
Kusek
This is how I have it setup but sharepoint doesn't seem to bind the events when the list is created
Michael Edwards