【问题标题】:EWS PullSubscription for New or Modified Calendar Events新的或修改的日历事件的 EWS PullSubscription
【发布时间】:2011-05-28 08:01:31
【问题描述】:

我一直在寻找一个 EWS 拉取订阅示例,该示例允许我获取自拉取订阅开始以来为用户创建或修改的日历事件的列表。我有工作代码来获取收件箱的此信息,但我还没有找到一个很好的例子来说明如何为日历执行此操作。

以下是收件箱的示例;谁能为我提供一个链接或代码示例,以使用 Exchange Web 服务拉订阅为日历事件或约会完成相同的事情?

    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/Modified - " + message.Subject);
                        }
                    } catch(Exception ex) {
                        MessageBox.Show("EventType.NewMail - " + itemEvent.ItemId);
                    }
                    break;
            }
        }
    }

【问题讨论】:

  • 你的问题已经回答了我的问题;)

标签: c# .net exchangewebservices


【解决方案1】:

只需订阅日历,而不是使用指定的事件类型订阅您的收件箱。

var subscriptionCalendar = service.SubscribeToPullNotifications(
    new[] { new FolderId(WellKnownFolderName.Calendar) }, 
    1440, 
    null, 
    EventType.Created, EventType.Modified);

或者,您可以为 FolderId(WellKnownFolderName.Inbox)FolderId(WellKnownFolderName.Calendar) 创建一个拉取通知,其中包含您想要的 EventType

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-21
    • 1970-01-01
    • 2014-02-05
    相关资源
    最近更新 更多