0

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
);
Pixelmonster
  • 396
  • 7
  • 15
  • 4
    Have you tried with EventType.Moved? because when you delete contact it will move to deleted items. – Jageen Jul 16 '13 at 09:45
  • 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 Jul 16 '13 at 12:41
  • @Jageen it's actually true only for exchange-server 2013| cf http://msdn.microsoft.com/en-us/library/office/dn424761(v=exchg.150).aspx – gilles emmanuel Sep 04 '14 at 10:36

2 Answers2

6

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, "usersemail@domain.com");
        var item = Item.Bind(service, notification.ItemId);
      }
    }
}
nmnd
  • 105
  • 12
Andy
  • 1,080
  • 5
  • 20
  • 35
  • I guess that's the answer I should accept, but I can't try your solution, because I'm not longer working in that business. – Pixelmonster Apr 26 '14 at 13:04
2

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>
Jageen
  • 6,345
  • 2
  • 37
  • 56
  • can you afford to use SyncFolderItems , http://msdn.microsoft.com/en-us/library/exchange/ee693003%28v=exchg.80%29.aspx – Jageen Jul 16 '13 at 09:07
  • Of course I could change the code to use SyncFolderItems, and I really thank you for this solution, but it doesn't solve my question, because I think there has to be another solution with StreamingNotifications only. Or did Microsoft really forget about that? – Pixelmonster Jul 16 '13 at 09:16
  • 1
    As i know StreamingSubscription is not supported in exchange 2007, and you are right there may be another solution, i will share if i got something. – Jageen Jul 16 '13 at 09:28
  • I have same quastion. On my Exchange2010 SP1 i delete with: shift+delete. Deleted Appointment does not appear in the folder "deletedItems". But i still get notification => moved. – Roma Kap Sep 12 '16 at 12:46