Search code examples
c#.netexchangewebservices

How to subscribe for push notifications for any user defined folder using EWS managed API


I am subscribing to push notifications as below:

var subscription = myExchangeService.SubscribeToPushNotifications(
                                    new[] { new FolderId(WellKnownFolderName.Inbox) },
                                    new Uri(somePostBackUrl),
                                    15,
                                    null,
                                    EventType.NewMail,
                                    EventType.Created,
                                    EventType.Deleted,
                                    EventType.Modified,
                                    EventType.Moved,
                                    EventType.Copied);

Now my requirement is to subscribe for notifications for any user defined folders as well. So 1) How can I get the list of all subfolders/userdefined folders. 2) how can I subscribe to a list of those folders?


Solution

  • 1) How can I get the list of all subfolders/userdefined folders.

    You need to use FindFolders to list the subfolders of whatever parent Folder you want to look at https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.folder.findfolders(v=exchg.80).aspx If you want to recuse to grandchildren of those folder set the traversal property of the FolderView class https://msdn.microsoft.com/EN-US/library/microsoft.exchange.webservices.data.folderview.traversal(v=exchg.80).aspx to Deep.

    . 2) how can I subscribe to a list of those folders?

    Once you have the FolderId from the above FindFolders call you then subscribe to each folder in turn. The other option is to subscribe to all folders in the Mailbox eg https://msdn.microsoft.com/en-us/library/office/microsoft.exchange.webservices.data.exchangeservice.subscribetopushnotificationsonallfolders(v=exchg.80).aspx