4

I created a simple event receiver of SPEmailEventReceiver. But while creating it, Visual Studio did not ask me on which list/library it needs to be attached. In PowerShell I know that I can get event receivers like this.

$site = Get-SPSite -Identity "SITE"
$web = $site.RootWeb
$list = $web.Lists["LIST/LIBRARY"]
$list.EventReceivers | Select assembly, name, type

But how can I check where the SPEmailEventReceiver event receiver is attached?

Update 1:

I have used ListTemplateId="101" while defining the event receiver so this should be applicable to all lists/libraries, right? For this how to know check where the event receiver is attached?

3

You inherit a SharePoint site. Some of the lists do odd things and you want to find out if there are there event receivers on the list. If you have access to Power Shell and the SharePoint servers, you can use the following Power Shell code to find out.

Code :

$GC = Start-SPAssignment            
$Site =  $GC | Get-SPSite http://yourserver/sites/yoursite            
$Web = $Site.Rootweb            
$Web.Lists |            
   Where {$_.EventReceivers.Count -gt 0} |            
   Select Title,EventReceivers |            
   Format-List            
Stop-SPAssignment $GC

Code For SharePoint 2007 or 2010 :

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")                        
$Site = New-Object Microsoft.SharePoint.SPSite(http://yourserver/sites/yoursite)                        
$Web = $Site.Rootweb                        
$Web.Lists |                        
   Where {$_.EventReceivers.Count -gt 0} |                        
   Select Title,EventReceivers |                        
   Format-List                        
$Web.Dispose()                        
$Site.Dispose()

You could even start at the farm (root) level and drill down to applications, site collections, sites and documents to see each event receiver!

  • So, the above code will give me all the event receivers for all the lists/libraries for the site? Also where do Email Event Receivers get attached? Also please see the edit to my question for more detail. – Naveen Jan 8 '16 at 4:49
  • Yes, This code will give you all the receivers which is connected all the lists in sites. you can attacjed email event receiver to document library as well as lists. – Dipen Shah Jan 8 '16 at 5:08
  • So if I have ListTemplateId="101" in my elements.xml then where will I see the event attached to? Will it be shown for all lists/libraries? – Naveen Jan 8 '16 at 16:44
0

You can add event receiver in element.xml for library as below.

--> It will not seen for all site and sub site. It will applied on only one list instance which is mention by user in Name property of below code.

Code:

 <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <Receivers ListTemplateId="101">
          <Receiver>
            <Name>ListName</Name>
            <Type>ItemAdded</Type>
            <Assembly>Test.eventreceiver.business, Version=1.0.0.0, Culture=neutral, PublicKeyToken=29192015d9531c48</Assembly>
          <Class>Test.eventreceiver.business.EventReceivers.Businesslogic</Class>
            <SequenceNumber>10000</SequenceNumber>
            <Synchronization>Synchronous</Synchronization>
          </Receiver>
      </Receivers>
    </Elements>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.