SHARE
TWEET

Untitled

a guest Aug 13th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private void AppInstalledMethod(SPRemoteEventProperties _properties)
  2.         {
  3.             using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(_properties, false))
  4.             {                
  5.                 if (clientContext != null)
  6.                 {
  7.                     Web web = clientContext.Web;
  8.                     var list = web.Lists.GetByTitle("MyDoc3");
  9.                     clientContext.Load(web);
  10.                     clientContext.Load(list);
  11.                     clientContext.Load(list.EventReceivers);
  12.                     clientContext.ExecuteQuery();
  13.  
  14.                     EventReceiverDefinitionCreationInformation receiver = new EventReceiverDefinitionCreationInformation();
  15.                     receiver.EventType = EventReceiverType.ItemAdding;
  16.                     OperationContext op = OperationContext.Current;
  17.                     Message msg = op.RequestContext.RequestMessage;
  18.                     receiver.ReceiverUrl = msg.Headers.To.ToString();
  19.                     receiver.ReceiverName = "ItemAddingEvent";
  20.                     receiver.Synchronization = EventReceiverSynchronization.Synchronous;
  21.                     receiver.SequenceNumber = 5000;
  22.                     list.EventReceivers.Add(receiver);
  23.  
  24.                     EventReceiverDefinitionCreationInformation receiverUpdate = new EventReceiverDefinitionCreationInformation();
  25.                     receiverUpdate.EventType = EventReceiverType.ItemUpdating;
  26.                     //op = OperationContext.Current;
  27.                     //msg = op.RequestContext.RequestMessage;
  28.                     receiverUpdate.ReceiverUrl = msg.Headers.To.ToString();
  29.                     receiverUpdate.ReceiverName = "ItemUpdatingEvent";
  30.                     receiverUpdate.Synchronization = EventReceiverSynchronization.Synchronous;
  31.                     receiverUpdate.SequenceNumber = 5000;
  32.                     list.EventReceivers.Add(receiverUpdate);
  33.  
  34.                     clientContext.ExecuteQuery();
  35.                 }
  36.             }
  37.         }
  38.  
  39.  
  40. public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
  41.         {
  42.             SPRemoteEventResult result = new SPRemoteEventResult();            
  43.             switch (properties.EventType)
  44.             {
  45.  
  46.                 case SPRemoteEventType.AppInstalled:
  47.                     AppInstalledMethod(properties);
  48.                     break;
  49.                 case SPRemoteEventType.AppUpgraded:
  50.                     AppUpgradedMethod(properties);
  51.                     break;              
  52.                 case SPRemoteEventType.ItemAdding:
  53.                     ItemAddingMethod(properties);
  54.                     break;
  55.                 case SPRemoteEventType.ItemUpdating:
  56.                     ItemUpdatingMethod(properties);
  57.                     break;
  58.                 case SPRemoteEventType.WebAdding:
  59.                     // you can implement webaddding event
  60.                     break;
  61.                 case SPRemoteEventType.WebDeleting:
  62.                 //you can implemet web deleting event if needed.
  63.                 default:
  64.                     break;
  65.             }
  66.             return result;
  67.  
  68.  
  69.  
  70.         }
  71.  
  72.         private void ItemUpdatingMethod(SPRemoteEventProperties _properties)
  73.         {
  74.             using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(_properties))
  75.             {
  76.                 if (clientContext != null)
  77.                 {
  78.                     var afterproperties = _properties.ItemEventProperties.AfterProperties;
  79.                 }
  80.             }
  81.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top