Get list of event receivers registered for a list created from a list definition

sharepoint.stackexchange https://sharepoint.stackexchange.com//questions/32091

  •  07-12-2019
  •  | 
  •  

Pergunta

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.

Foi útil?

Solução

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

Outras dicas

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.

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?

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/

Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top