SPList.ContentTypes.EventReceivers returns NULL

  • SPList.ContentTypes.EventReceivers returns NULL Brian

    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.

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

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

event-handlers content-type
Related questions and answers
  • I have never really had too much cause to use this method before but I am developing some generic classes to deal with column, content type and list management for use in a series of features. My...\Lists\ListHelper.vb:line 111 at XXXXXX_Feature_Receiver.XXXXXXDataStructureFeatureFactory.CreateOrUpdateListInstances(SPWeb Web) in C:\TestBed\XXXXXX Feature Receiver Development\XXXXXX..., this is the reason for my post. I cannot get this code to execute from within a console application. Does the SPList.SaveAsTemplate method require a HttpContext? If it does it is not metioned in any of the docs

  • So I did create on an SPWeb 20 custom lists and then a tasks list. For each of those 20 lists I've created 20 site lookup columns. I then created 20 Content Types based on Task content type. Then I've added each content type to the Tasks list. After that I've added each lookup site column to the corresponding list content type. So far so good. I've built a custom WebPart that displays task items...); Update: I've built a C# console app which creates all lists / lookup columns / content types and add the lookup column to corresponding content type. Result: same thing, same magic number 13. Anyone

  • . Scoped to Site. Registration: contains a ListTemplate and a ListInstance that just modifies a basic Custom List to enable content types and add my custom content type. Scoped to Web. Here's what's happening. When I activate ContentTypes, the content type and field are deployed as expected into my site collection. When I activate Registration, the list is provisioned and the content type is added as expected. When I try to add a new item to the list, the list form only shows the Title field from Item. Now, here's the weird part. If I add a second content type to the list (through the UI

  • My goal is to programmatically activate a Web Application scoped feature. I'm running this code from a feature receiver of a Web scoped feature. I'm logged in as a Farm Administrator. My app pool... } I also tried. public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWeb web = properties.Feature.Parent as SPWeb; SPSecurity.RunWithElevatedPrivileges( () => { SPSite elevatedSite = new SPSite(web.Site.ID); elevatedSite.WebApplication.Features.Add( /*guid*/ ); //throws SecurityException }); } I don't understand why I would

  • I have a webpart i build using WSpBuilder and it works OK. When i use Deploy from Visual Studio it installs the WSP sharepoint and add the webpart to the webpart gallery. But it seems the feature does activate the webpart but i also want to remove it when deactivating it.(So i know i need to add something to the FeatureDeactivating So i created a Feature With Reciever template and added...(SPFeatureReceiverProperties properties) { SPSite site = null; try { site = properties.Feature.Parent as SPSite; using (SPWeb web = site.RootWeb

  • , a new item added to the lookup list, as expected, but the content type of new item is always "Folder" instead of normal "Item". I have tested my field with different types of list but there is no issue...I have created a custom lookup field inherited from SPFieldLookup. It works exactly like SPLookupField but allows user to add new values. These new values gets added in the Lookup list and becomes... to the target list and then return the newly added item's "ID;#Value" pair. My Field is working fine if I add it in any list where "Folder" is not a default content type. For example, I can create

  • existing sties. New sites would pick it up via the feature. When I do this I can deactivate and reactivate the feature to correctly replace the home page with the "latest version". However, when I...This is in the context of MOSS 2007. I have a custom site definition. Currently in ONET.xml we have the following Module: <View List="$Resources:core,lists_Folder;/$Resources:core... to the Pages library. This correctly provisions the page to the Pages library with an Announcements List View web part provisioned to the page. I have about 800 (or so) sites created from this site definition

  • (I have also asked this question on Stack Overflow) I have a SharePoint feature I'm using to add some custom aspx files to the Pages Library. When I activate the feature, I can visit the pages 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: <?xml version="1.0" encoding="utf-8"?> <.../Pages/Example.aspx When I "View All Site Content" I am looking at the contents of the "Pages" list: http://myserver:PORT/subsite/Pages/Forms/AllItems.aspx

  • This is mainly a verification question as I have been fighting with an issue for a couple of days now. I have two lists derived from 2 custom content types. Both content types used the task base content type. Each of the derived content types have custom form rendering templates. I am using a custom usercontrol with codebehind added to the .ascx page as a control to redraw the forms differently... did on the other form. I am wondering if it is because both lists share the same type number (107) or if it might be something else. So does each list need to have a custom type number or does

Data information