2011-02-10 73 views
3

我寫Outlook 2010中的加載項在一個點上,它需要刪除當前由用戶選擇郵件項目。我使用下面的代碼,它工作得很好:在Outlook 2010的加載項中,如何使刪除操作可以撤消?

Selection selectedMessages = Globals.ThisAddIn.Application.ActiveExplorer().Selection; 

// It is possible for a non-mail item to be part of this collection. (One example is when a calendar 
// item is in the deleted items folder. Select it and hit this delete button.) 
System.Collections.IEnumerator enumerator = selectedMessages.GetEnumerator(); 
while(enumerator.MoveNext()) 
{ 
    if (enumerator.Current is MailItem) 
    { 
    ((MailItem)(enumerator.Current)).Delete(); 
    } 
} 

我的問題是,當我刪除郵件這種方式,正常的「撤銷」操作不提供給用戶。這可以使用戶去刪除郵件文件夾和郵件移動回到收件箱。但是,這將是對那些以前只是按下Ctrl-Z或在屏幕的左上角的小「撤消」箭頭用戶感到困惑。

是否有某種方式可以使用撤消機制註冊此操作,或者可以在消息上調用Outlook的「真實」刪除功能,以便撤消自動可用?

回答

1

不要刪除MailItem;請將其移至olFolderDeletedItems文件夾。您可以使用GetDefaultFolder()獲取對此文件夾的引用;見here

+0

感謝您的建議,但沒有做到這一點。它確實刪除郵件項目,但撤銷命令行爲與在MailItem上使用Delete方法相同。沒有撤消。 – 2011-02-10 22:12:17