我试图从outlook发送邮件之前获取附件路径。但是,当我尝试如此,结果null
。这里是我的代码:Outlook加载项无法读取附件路径
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
}
void Application_ItemSend(object Item, ref bool Cancel)
{
Outlook.MailItem mail = Item as Outlook.MailItem;
var atts = mail.Attachments;
foreach (Outlook.Attachment attachment in atts)
{
MessageBox.Show(attachment.PathName); // the PathName is null !
}
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
}
用户创建一个新的邮件,并添加附件,这已经是在硬盘。我如何获得所选文件的路径信息?
在发送电子邮件之前,我想将实际文件上传到FTP并用链接替换它。我做到了,但是我必须再次保存附件(暂时)以上传它们。我只是想知道,如果我可以直接上传附件而不做任何保存...... – 0014
不,你不能那样做。即使用户拖动文件,在发送邮件时也可能会消失。在MAPI中,您可以直接访问PR_ATTACH_DATA属性(将其作为IStream打开),但与通过网络发送数据相比,保存文件(Attachment.SaveAsFile)的性能可忽略不计。 –