0
votes

When an element is created or a modified on an Exchange Server I get a StreamingNotification with an unique id and other information about that contact/calendar, but how could I get information about a deleted item?

Where do I get the id from? Or at least the first e-mail-address or the subject?


I'm using EWS Managed API and here's my code:

StreamingSubscription subscription =
ser.SubscribeToStreamingNotifications(
    new FolderId[] { WellKnownFolderName.Contacts,
    WellKnownFolderName.Calendar },
    EventType.Created,
    EventType.Modified,
    EventType.Deleted
);
2
Have you tried with EventType.Moved? because when you delete contact it will move to deleted items. - Jageen
Now I tried it with the Moved Event, but there is one little problem left: When you select one or more users and press Shift + Delete they get deleted permanently, so this workaround doesn't work. - Pixelmonster
@Jageen it's actually true only for exchange-server 2013| cf msdn.microsoft.com/en-us/library/office/… - gilles emmanuel

2 Answers

6
votes

Streaming Notifications will not generate a "Delete" event. In both cases of delete, delete or shift+delete, the Item is actually "Moved" to the one of the deleted Items Folder. A regular delete moves your item to the "DeletedItems" Folder. Exchange maintains a dumpster folder in which all your "shift+del" items are sent to. It is possible to recover them, but a little harder.

You can read more about the Deletion mechanism of Exchange in these articles:

  1. http://msdn.microsoft.com/en-us/library/office/dn424760(v=exchg.150).aspx
  2. http://technet.microsoft.com/en-us/library/ee364755(v=exchg.150).aspx

Now coming back to recover the deleted items, 2 important things to note

  1. You should have Impersonation access on the person's mailbox for whom you are trying to recover the item. Delegation access wont let you search for items in the RecoverableItems Folder where you will find your deleted items.

  2. ItemId of the deleted item will change. ItemId in Exchange is only unique to the Folder. When an item is moved between folders, its ItemId changes. However, the old ItemId is found in the Streaming events property OldItemId

The following code snippet will let you get a handle on the deleted item.

private void OnNotificationEvent(object sender, NotificationEventArgs args)
{
    foreach (var notification in args.Events.OfType<ItemEvent>())
    {
      if (notification.EventType == EventType.Moved)
      {
        ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "[email protected]");
        var item = Item.Bind(service, notification.ItemId);
      }
    }
}
2
votes

You can use Subscribe operation or SyncFolderItems operation to get deleted item id.
referance :-
http://msdn.microsoft.com/en-us/library/exchange/aa566188%28v=exchg.80%29.aspx
http://msdn.microsoft.com/en-us/library/exchange/aa563967%28v=exchg.80%29.aspx
I develop this in iOS, but i think you are using EWSAPI in c# so that i can not share code.

In Subscription operation you can specify event type "DeletedEvent" to get notification.
and in SyncFolderItems operation you will get deleted item in tag "Delete" under "Changes"

<Changes>
   <Create/>
   <Update/>
   <Delete/>
</Changes>