我正在爲outlook 2013開發一個插件。它是一個示例項目,我想要做的是從mailitem中刪除所有附件。這就是我要做的事使用vsto從outlook mailitem中刪除附件
while (mail.Attachments.Count > 0)
{
try
{
mail.Attachments.Remove(1);
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
}
編輯:我也嘗試過的方式與倒 for循環(for i = mail.Attachments.Count; i > 1; i--
)將其刪除,但得到了同樣的結果
,它工作正常除外事實上,它拋出在控制檯上此異常:在PCMailAddIn.dll
「System.Runtime.InteropServices.COMException」拋出異常:
拋出異常: mscorlib.dll中的'System.Reflection.TargetInvocationException'
//另一種方式 //刪除全部附件()ToList(); if(attachments.Any()) { attachments.Reverse(); attachments.ForEach(att => mailItem.Attachments.Remove(att.Index)); } –
Guest1979
變種附件= mailItem.Attachments.Cast