6

I created a list definition created from visual studio. I also have an event receiver specified along with the listtemplate feature. The idea was to have event receiver registered for all lists created from this definition. List and event receiver is working as expected (even for new lists created).

I noticed today that, if I access the SPList.EventReceivers.Count (via powershell/object model/ SP Manager), the count is always 0. But if I create new event receiver (new project) and bind it to the list, the assemebly shows up in SPList.EventReceivers

So my question is if I have a custom list definition with an event receiver why is the SPList.EventReceivers.Count 0 even though there is an event receiver attached to it.

Edit: Also verified using SharePoint Manager tool.

4 Answers 4

8

Finally traked it down.

The event receiver was listed under SPSite.EventReceivers.

As per msdn, the event receiver will be registered as per the scope specified (seems to default to feature scope). As my feature (which contained list template and event receiver) was deployed using scope=site, the event is listed under spsite.eventreceivers (registered event receiver to all lists of the specified list template type in the site collection).

Scoping the feature to web registered the receiver to all list of the particular web. SPList.EventReceivers had the specified event receiver name this time. Using ListUrl attribute instead of ListTemplateId registered the event receiver to a particular list instance.

Can someone add more information.

See Receiver element Schema

1
  • I have similar problem. I have an orphan receiver which "<Receivers ListTemplateId="115" >. Scope it not defined. Now the receiver generate error msg in event log Could not load file or assembly xxx I have tried with PowerShell, featureadmin, SP manger all cannot find the orphan receiver.
    – Mark L
    Commented Feb 21, 2017 at 5:23
1

The simplest way (non-coded solution) is to download http://spm.codeplex.com/

you can run SharePoint Manager on your SharePoint server (make sure you do a 'run as administrator' for the first time), then just navigate to your appropriate list, and open up event receivers. It will display everything attached.

This is a great tool for determining precisely what exists where on your site, and i definitely recommend you get it, even if you prefer to come up with a coded solution for this particular problem.

3
  • Forgot to mention that, I did verify it with SharePoint manager tool. The property is empty.
    – sssreddy
    Commented Mar 21, 2012 at 0:04
  • Do me a favor and check the content type definition in SharePoint Manager then, i just finished checking my dev server, but i dont have any event receivers set up that way
    – Zork
    Commented Mar 21, 2012 at 0:21
  • Nope. Is empty.
    – sssreddy
    Commented Mar 21, 2012 at 2:52
0

This might be a long shot, but when you created your list definition, did you bind the event reveiver to the actual list, or to a content type that you also created as part of the list definition?

1
  • I have binded using list template Id "<Receivers ListTemplateId="" >. It was deployed along with the same feature that deploys the corresponding list definition and it is working. But I am not sure if SPList.EventReceivers is supposed to be 0 (is it expected behaviour?)
    – sssreddy
    Commented Mar 21, 2012 at 3:04
0

You can generate a CSV output of all event receivers, using this script I wrote:

$wa=Get-SPWebApplication http ://SharePoint  #susbstitute with your own Web Application.

foreach ($site in $wa.Sites)
{
Write-Host "S" -NoNewline
    foreach ($web in $site.allwebs)
    {
    Write-Host "W" -NoNewline

        for ($LibIndex=0; $LibIndex -lt $web.Lists.Count; $LibIndex++)
        {
        Write-Host "L" -NoNewline
            $list = $Web.Lists[$LibIndex];

            $i=0;

            foreach ($ER in $list.EventReceivers)
            {
                Add-Content C:ReportsERs.csv "$($Site.url),$($web.title),$($web.url),$($List.title), Event $($i): $($ER.name), $($ER.Synchronization)"
                $i++
            }

        }
    }
}

http://www.reality-tech.com/reporting-on-sharepoint-event-receivers/

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.