×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: C#
Posted by: Arturo Bardelli
Added: Jan 7, 2016 2:18 PM
Views: 23
Tags: no tags
  1. Programmatically
  2.  
  3. [code lang="csharp"]
  4.  
  5. MyEventReceiver eventReceiver = new MyEventReceiver();
  6.  
  7. SPEventReceiverDefinitionCollection eventReceiverCol = myList.EventReceivers;
  8.  
  9. SPEventReceiverDefinition eventReceiverDef = eventReceiverCol.Add();
  10.  
  11. eventReceiver.Name = “My Event Receiver”;
  12.  
  13. eventReceiver.Synchronization = SPEventReceiverSyncronization.Synchronous;
  14.  
  15. eventReceiver.Type = SPEventReceiverType.ItemAdded;
  16.  
  17. eventReceiver.SequenceNumber = 100;
  18.  
  19. eventReceiver.Assembly = Assembly.GetExecutingAssembly().FullName;
  20.  
  21. eventReceiver.Class = eventReceiver.GetType().ToString();
  22.  
  23. eventReceiver.Update();
  24.  
  25. [/code]
  26.  
  27. Using XML
  28.  
  29. [code lang="xml"]
  30.  
  31. <Receivers >
  32.  
  33. <Receiver>
  34.  
  35. <Name>MyEventReceiver</Name>
  36.  
  37. <Type>ItemAdded</Type>
  38.  
  39. <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
  40.  
  41. <Class>MySolution.EventReceivers.MyEventReceiver</Class>
  42.  
  43. <SequenceNumber>100</SequenceNumber>
  44.  
  45. <Synchronization>Synchronous</Synchronization>
  46.  
  47. </Receiver>
  48.  
  49. </Receivers>
  50.