挂钩发送/接收Outlook联系人的同步事件
题
如何使用VSTO AddIn为Outlook 2007中的联系人文件夹/联系人项目的 SendAndReceive
事件附加事件处理程序?我尝试使用:
Application.ActiveExplorer().SyncObjects.ForEach
{
SyncObject.SyncEnd += \\Do something
}
但它没有用。
解决方案
我试过
Application.ActiveExplorer().SyncObjects.AppFolders.SyncEnd += \\EventHandler
此挂钩发送/接收所有默认文件夹..
其他提示
实际上我的需求有点不同但可能是相同的: 我希望在发送/接收后收到有关文件夹更改(我的情况下的约会)的通知。 我的第一个想法(我认为你在同一轨道上)是检查发送/接收事件,并且可能从它或类似的东西中获得一些项目的集合,但是没有这样的东西可用。 (如中所述)这个论坛帖子)
我的第二条路径来自以下文章:我可以注册到文件夹的 Item_Add
和 Item_Change
(甚至 Item_Removed
)事件(这些事件也由更改触发)由发送接收完成):
一些代码:
// Get the folder calendar folder and subscribe to the events.
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar).Items.ItemAdd += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar).Items.ItemChange += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemChangeEventHandler(Items_ItemChange);
}
// Do something with it.
void Items_ItemAdd(object Item)
{
logItem(Item, "Add");
}
void logItem(object Item, string Action)
{
Outlook.AppointmentItem item = Item as Outlook.AppointmentItem;
File.AppendAllText(@"e:\log.txt", string.Format("Item {0}: {1}", Action, Item));
if (item != null)
{
File.AppendAllText(@"e:\log.txt", " - Appointment: " + item.Subject);
}
}
您可以挂接邮件发送/接收事件,然后检查邮件类型是否为ContactItem。以下是Send事件的示例。
// hook up the event
this.Application.ItemSend += ThisApplication_SentMail;
然后在您的事件处理程序中检查邮件项类型;
internal void ThisApplication_SentMail(object item, ref bool cancel)
{
Outlook.ContactItem contactItem = item as Outlook.ContactItem;
// mail message is not a ContactItem, so exit.
if (contactItem == null) return;
// do whatever you need to here
}
不隶属于 StackOverflow