Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AppEventReceiver : IRemoteEventService
- {
- public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
- {
- SPRemoteEventResult result = new SPRemoteEventResult();
- using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false))
- {
- if (clientContext != null)
- {
- clientContext.Load(clientContext.Web, ev=>ev.EventReceivers);
- clientContext.ExecuteQuery();
- // Create new List Added Event Receiver
- EventReceiverDefinitionCreationInformation listAddedEV = new EventReceiverDefinitionCreationInformation()
- {
- EventType = EventReceiverType.ListAdded,
- ReceiverName = "List_Events",
- ReceiverUrl = GetServiceURL("List_Events.svc"),
- SequenceNumber = 1000
- };
- // Add Event Receiver to Web's EventReceivers.
- EventReceiverDefinitionCollection webEvs = clientContext.Web.EventReceivers;
- List<EventReceiverDefinition> existingEvs = webEvs.Where(n => n.ReceiverName == "List_Events").ToList(); // Error is here!
- foreach (EventReceiverDefinition ev in existingEvs)
- {
- ev.DeleteObject();
- }
- // Add event receiver to Projects List
- webEvs.Add(listAddedEV);
- clientContext.ExecuteQuery();
- }
- }
- return result;
- }
- context.Credentials = new NetworkCredential("user", "password", "domain");
- var existingEvs = webEvs.ToList().Where(n => n.ReceiverName == "List_Events").ToList();
Add Comment
Please, Sign In to add comment