【问题标题】:In an add-in for Outlook 2010, how can I make a delete operation undo-able?在 Outlook 2010 的加载项中,如何使删除操作能够撤消?
【发布时间】:2011-06-25 03:07:25
【问题描述】:

我正在为 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 的“真正”删除功能,以便自动撤消?

【问题讨论】:

    标签: c# outlook pia outlook-2010


    【解决方案1】:

    不要删除MailItem;将其移至 olFolderDeletedItems 文件夹。您可以使用GetDefaultFolder() 获取对该文件夹的引用;见here

    【讨论】:

    • 感谢您的建议,但没有这样做。它确实删除了邮件项,但撤消命令的行为与在 MailItem 上使用 Delete 方法相同。没有撤消。
    • 联系人也一样吗?我现在正在尝试删除它们,但也许我应该将它们移至olFolderDeletedItems。但是,我希望我的联系人永远消失。有olFolderReallyReallyTrulyDeletedItems.这样的文件夹吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-17
    • 2020-04-17
    • 2013-11-14
    • 1970-01-01
    • 2012-08-24
    • 1970-01-01
    相关资源
    最近更新 更多