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

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

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
{
    get
    {
        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".

share|improve this answer
    
@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' –  Charles Lee May 11 '10 at 13:27
add comment

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?

Updated

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?

share|improve this answer
    
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 May 11 '10 at 12:37
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.