我正在为 Outlook 开发一个 C# 插件,该插件将在将项目添加到“已删除邮件”文件夹时起作用。粗略地说,代码如下所示。添加该方法时,我看到了日志通风口,但是当我删除一个项目时,其他日志事件不会被触发。我错过了什么?
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
try
{
Outlook._Application olApp = new Outlook.ApplicationClass();
Outlook._NameSpace olNS = olApp.GetNamespace("MAPI");
Outlook.MAPIFolder deletedFolder = olNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems);
deletedFolder.Items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(DeletedItems_ItemAdd);
log("addDeletedItemEventHandler method added", LogLevel.Debug);
}
catch (Exception e)
{
log("Exception in addDeletedItemEventHandler: " + e.Message, LogLevel.Error);
}
}
private void DeletedItems_ItemAdd(object Item)
{
log("DeletedItems_ItemAdd - Fired", LogLevel.Debug);
}
德米特里的解决方案是正确的。对于希望解决此问题的其他任何人:
我在类级别定义了以下内容: Outlook.Items oiDeletedFolderItems;
在 OnConnection 方法中,我添加/更改了:oiDeletedFolderItems = deletedFolder.Items; oiDeletedFolderItems.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(DeletedItems_ItemAdd);