1

I'm trying to create a feature to register my event handler to a specific list. I'm building it like I would a normal feature. However, I'm not sure how to define my Elements file. The file for my feature is as follows:

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers ListTemplateId="101">
    <Receiver>
        <Name>AddedEventHandler</Name>
        <Type>ItemAdded</Type>
        <SequenceNumber>10000</SequenceNumber>
        <Assembly>ChangeContentTypeEventHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7bfc7c17f98031d7</Assembly>
        <Class>ChangeContentTypeEventHandler.ChangeContentTypeEventHandler</Class>
        <Data></Data>
        <Filter></Filter>
    </Receiver>
</Receivers>
</Elements>

Based on this, how would I set up the file for registration of this event handler?

Also, here is my Feature.xml file:

<?xml version="1.0" encoding="utf-8" ?>
<Feature Scope="Web" Title="Change Content Type Event Handler"
  Id="{27C2FDFF-ADA0-4984-955C-6448E182FA88}"
  xmlns="http://schemas.microsoft.com/sharepoint/">
    <ElementManifests>
        <ElementManifest Location="ListTemplates\ListManifest.xml"/>
        <ElementFile Location="Messages\schema.xml"/>
    </ElementManifests>
</Feature>

Also, can this be part my solution package WSP for the feature itself so that it gets deployed with the feature?

Thanks in advance

1 Answer 1

1

Yes, you can package your feature and the associated element manifest file and your dll containing the item event receiver code into a wsp. After your solution is deployed, you can activate the feature on your site and the ItemAdded event will be registered.

The part that you cannot accomplish using this method is to "register my event handler to a specific list". Using this declarative method, you are binding your ItemAdded to all lists of type ListTemplateId="101", which is all document libraries. You can do this, but the first line of your event reciever will need to check the name of the list to see if it is the one your want.

If you want to only execute your ItemAdded code on one specific list, you will need to write code to bind your event receiver to that list. Or, you can create a content type for your list and in the definition of the content type include your event receiver information.

2
  • My code handles checking for which list, but it doesn't seem to register to the document library (101). The feature gets installed and activated, but the event handler doesn't run until I register the event handler to the list in Sharepoint Event Handler Manager. Surely, there's another way to make this happen in the installation package
    – Music Magi
    Commented Jun 13, 2011 at 15:19
  • Can you check the logs to see if there is an exception being thrown when you activate your feature? Maybe the name of your assembly or class is incorrect. Is your namespace ChangeContentTypeEventHandler and your class name is also ChangeContentTypeEventHandler?
    – Laurie
    Commented Jun 13, 2011 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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