I am trying to create a feature that uses the API for associating an ItemAdded event receiver to a Discussion List. I was associating the Event Receiver to the SPList, however, i don't want the event to fire when Replies are created (Message Content Type), only when Threads (i.e. Discussion Content Types) are created.

In my situation, I have a Feature Receiver and essentially the following code:

SPWeb web = properties.Feature.Parent as SPWeb;
if (web.Lists["Team Discussion"].ContentTypes["Discussion"].EventReceivers == null)
  throw new Exception("null ...darn");

Will SharePoint allow me to associate event receivers on particular lists content types?

In this case, if the users add additional discussion boards, I don't want to register them with my event reciever, so I don't want to add the association at the web level.

EDIT: I actually need to handle ItemAdded, ItemUpdated, and ItemDeleted, not just ItemAdded. The CUD on the list is not very intensive, however, there are a few hundred instances of the list. I am aware of creating a new Content Type, however, this will require backporting hundreds of lists and migrating each OOB Discussion ListItem to a new Custom Discussion Content Type, not to mention will require testing to see if SPUtility.CreateNewDiscussion() will play nicely with the new custom Discussion CType.

2 Answers 2


Actually, it doesn't look like this is possible.

Using Reflector, here is the definition of the EventReceivers property for the SPContentType:

public SPEventReceiverDefinitionCollection EventReceivers
        return ((this.m_list != null) ? null : this.GetEventReceivers());

So you can see, it's basically saying: "If the m_list is not null (i.e. we are looking at a List Content Type instance), then always return null".

  • @Brian - This is an update to your question really and would be better located within an edit to your original question rather than as an 'answer' Commented May 11, 2010 at 13:27

Would it not be better to just add some logic within your event receiver itself to ignore other content types and only take action on Discussion Content Types?


In response to your comment. Your question only mentions 'creation' which is why I suggested this approach. In terms of performance is this a CRUD heavy list? What sort of volume are we talking?

  • Charles, I assume you mean to add the Event Receiver to the SPList containing the Content Type and put checks in the Event Receiver logic to only process items with my particular content type. This is what I am doing, but it's not optimal for my situation for the following reasons: 1. Handling ItemDeleted we have no way of knowing what type of object my item was because of the nature of the data ItemDeleted exposes. 2. Unneccessary logic firing = unneccessary load on my WFE/APP server(s).
    – Brian
    Commented May 11, 2010 at 12:37

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.