1

I have an event receiver I developed with Visual Studio that I want to deploy. But in this case I want to deploy it without associating it with any list. (I add the event receiver to a specific list later via PowerShell.)

I know that if I set the Scope to Site then the receiver will fire for all lists and libraries. And I know that if I set the Scope to Web and provide a value for ListUrl then it will only bind to the specified list.

However, it seems that if I set the Scope to Web and do not specify a ListUrl, it acts the same as Site and binds to everything. Here is my code

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers Scope="Web">
    <Receiver>
      <Name>AutoNumberDocumentItemAdded</Name>
      <Type>ItemAdded</Type
      <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
      <Class>ArticleManagementWorkflow.AutoNumberDocument.AutoNumberDocument</Class>
      <SequenceNumber>10000</SequenceNumber>
      <Synchronization>Synchronous</Synchronization>
    </Receiver>
  </Receivers>
</Elements>

Is there a way to deploy and activate the receiver without it being bound to anything?

  • 1
    Can't you scope it do web without activating the feature, and activate the feature in your powershell script when you run that? – Anders Aune Mar 25 '14 at 6:37
  • Deploy the event receiver and do not activate the Feature.The elements file only attaches the event receiver to list when feature is activated. Attach the event receiver to list from your powershell afterwards – Unnie Mar 25 '14 at 7:17
  • @Unnie -- That was the solution. You just gave me a better understanding of the role the elements file plays. Feel free to retype it as an Answer so I can mark it and give credit. Thank you. – Jason Mar 25 '14 at 13:37
2

Deploy the event receiver and do not activate the Feature.The elements file only attaches the event receiver to list when feature is activated. Attach the event receiver to list from your powershell afterwards.

2

There is another option how to add Event Receiver to a specific List - add the Event Receiver to the Content Type.

Steps:

  • Create custom Content Type for a List
  • Add the Event Receiver to the Content Type
  • Add Content Type to a specific List in order to register the Event Receiver

In that case you will be able to control on which List an Event Receiver should be registered.

Please refer a great article Walkthrough 3 – Developing an Event Receiver for a Content Type for a more details.

  • That is a great suggestion but in this case the event performs a rename on any item added to the list or library. It is not specific to any content type but instead can be turned on/off for any given list. – Jason Mar 25 '14 at 13:39
1

In your case you don't need a feature.
All you need is a class library with your event receiver class, sign the assembly and deploy it to GAC. Then with PowerShell register the event receiver for the list you want.

  • Unnie suggested the same thing earlier. That is what I ended up doing. I was already deploying a DLL as part of my overall solution but it was for a supporting class used to serialize a workflow association data class. I was not aware that I could deploy (and more importantly attach) event receivers without including an elements.xml file. – Jason Mar 25 '14 at 13:42
0

How about attaching it to a dummy list which does not actually exist in the web and then later attaching it to the actual list using Powershell.

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.