我知道如何将文件添加到 MailItem.Attachments 但如何检查文件是否已添加到附件?
例如,我有文件名"C:\\myFolder\\myFile.txt"
. 如何检查此文件是否已附加?我需要这个来防止将文件重复附加到新电子邮件中。
这是我到目前为止所拥有的:
var mItem = Outlook.Interfaces.HostAddIn.Application.ActiveInspector().CurrentItem as MailItem;
if (mItem != null)
{
//this works fine but I need to check if already attached first like below
//mItem.Attachments.Add(localFilePath);
bool found = false;
string attachments = "";
for (int i = 1; i <= mItem.Attachments.Count; i++)
{
attachments +=
"DisplayName: " + mItem.Attachments[i].DisplayName //shows just myFile.txt, no path
+ " / FileName: " + mItem.Attachments[i].FileName //shows just myFile.txt, no path
+ " / PathName: " + mItem.Attachments[i].PathName; //shows ""
//I tried here PathName, FileName, DisplayName but all return just name, without the path
if (mItem.Attachments[i].PathName == localFilePath)
{
found = true;
}
}
if (!found)
{
mItem.Attachments.Add(localFilePath); //attach only if not already attached
}
}