none
EWS PullSubscription for New or Modified Calendar Events RRS feed

  • Question

  • I have been searching for an EWS pullsubscription example that allows me to get a list of calendar events that have been created or modified for a user since the pull subscription has been started. I have working code to get this info for the Inbox but I haven't found a good example for how to do this for the Calendar.

    Below is an example for the Inbox; can anyone provide me with a link or a code example to accomplish the same thing for Calendar events or appointments using an Exchange Web Service pull subscription?

     

        ExchangeService service;

        PullSubscription subscriptionInbox;


        private void SetService() {

            service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);

            service.Url = new Uri("https://mail.myserver.com/EWS/Exchange.asmx");

        }


        private void SetSubscription() {

            if(service == null) {

                SetService();

            }

            // Subscribe to pull notifications in the Inbox folder, and get notified when

            // a new mail is received, when an item or folder is created, or when an item

            // or folder is deleted. 

            subscriptionInbox = service.SubscribeToPullNotifications(

            new FolderId[] { WellKnownFolderName.Inbox },

            5 /* timeOut: the subscription will end if the server is not polled within 5 minutes. */,

            null /* watermark: null to start a new subscription. */,

            EventType.NewMail, EventType.Modified);

        }


        private void btnGetLatestMessages_Click(object sender, EventArgs e) {

            if(subscriptionInbox == null) {

                SetSubscription();

            }

            GetEventsResults eventsInbox = subscriptionInbox.GetEvents();

            EmailMessage message;

            // Loop through all item-related events.

            foreach(ItemEvent itemEvent in eventsInbox.ItemEvents) {

                switch(itemEvent.EventType) {

                    case EventType.NewMail:

                        try {

                            Item item = Item.Bind(service, itemEvent.ItemId);

                            if(item.ItemClass.ToLower() == "IPM.Note".ToLower()) {

                                message = EmailMessage.Bind(service, itemEvent.ItemId);

                                MessageBox.Show("Inbox/NewMail - " + message.Subject);

                            }

                        } catch(Exception ex) {

                            MessageBox.Show("EventType.NewMail - " + itemEvent.ItemId);

                        }

                        break;

                    case EventType.Modified:

                        try {

                            Item item = Item.Bind(service, itemEvent.ItemId);

    if(item.ItemClass.ToLower() == "IPM.Note".ToLower()) {

                                message = EmailMessage.Bind(service, itemEvent.ItemId);

                                MessageBox.Show("Inbox/NewMail - " + message.Subject);

                            }

                        } catch(Exception ex) {

                            MessageBox.Show("EventType.NewMail - " + itemEvent.ItemId);

                        }

                        break;

                    case EventType.Modified:

                        try {

                            Item item = Item.Bind(service, itemEvent.ItemId);

                            if(item.ItemClass.ToLower() == "IPM.Note".ToLower()) {

                                message = EmailMessage.Bind(service, itemEvent.ItemId);

                                MessageBox.Show("Inbox/Modified - " + message.Subject);

                            }

                        } catch(Exception ex) {

                            MessageBox.Show("EventType.NewMail - " + itemEvent.ItemId);

                        }

                        break;

                }

            }

        }

    Monday, May 23, 2011 6:05 PM

All replies

  • this is what i use
    var folderId = new DistinguishedFolderIdType();
    folderId.Id = DistinguishedFolderIdNameType.calendar;
    Tuesday, May 24, 2011 11:37 AM