0
ストリームリスナーを使用してカレンダー通知を取得しようとしています。EWS exchange - NotificationEventをItemEventにキャストするときのnull参照
インターネット上では、例はほとんど同じように見えます。しかし私の場合、ItemEventをItemEventにキャストしてItemIdをキャストすると、キャストは正常に実行されますが、オブジェクトは常にnullです。内部的にNotificationEvent
はFolderEvent(ItemIdはありません)です。とにかく、すべての例で常にItemEventにキャストされます。あなたが最初
if (notification is ItemEvent)
{
// The NotificationEvent for an e-mail message is an ItemEvent.
ItemEvent itemEvent = (ItemEvent)notification;
}
else
{
// The NotificationEvent for a folder is an FolderEvent.
FolderEvent folderEvent = (FolderEvent)notification;
}
フォルダのイベント通知は、基本的にあなたがいることを知っている通知等の種類をチェックする必要がありますので、あなたは両方のアイテムとフォルダの通知イベントに加入している何種類によって
public void OnNotificationEvent(object sender, NotificationEventArgs args)
{
foreach (NotificationEvent notification in args.Events)
{
ItemEvent itemEvent = notification as ItemEvent;
... //Other code goes here
}
}
それは、あなたが言う同じように感謝です。とにかく、私はItemEventを受け取り、FolderEventを無視することができますか?どうやって? –
変更のイベントに登録したときなど、FolderとItemの両方に通知が届いたときなど、FolderEventを無視する必要があるだけです。 –