C# 使用EWS提取内联图像

C# 使用EWS提取内联图像,c#,exchangewebservices,C#,Exchangewebservices,我正在使用EWS从exchange 2013提供的电子邮件中读取和提取图像。使用下面的代码,这是伟大的工作时,图像作为实际附件。。当图像作为内联附件传递时,问题就出现了 对于内联附件,EWS.hasaAttachments不会返回true。。没有想到这一点似乎很愚蠢。。阅读下面的文章似乎有一个解决办法,但我只是想知道什么是检索常规和内联图像附件并将其保存到目录的最佳、最有效的方法 }看起来你从第一行中得到了一些灵感。您不需要检查HasAttachments,只需遍历mail.Attachmen

我正在使用EWS从exchange 2013提供的电子邮件中读取和提取图像。使用下面的代码,这是伟大的工作时,图像作为实际附件。。当图像作为内联附件传递时,问题就出现了

对于内联附件,EWS.hasaAttachments不会返回true。。没有想到这一点似乎很愚蠢。。阅读下面的文章似乎有一个解决办法,但我只是想知道什么是检索常规和内联图像附件并将其保存到目录的最佳、最有效的方法


}

看起来你从第一行中得到了一些灵感。您不需要检查
HasAttachments
,只需遍历
mail.Attachments
本身即可

foreach (var attachment in mail.Attachments.Where(a => a is FileAttachment && a.ContentType == "image/jpeg"))
{
    Console.WriteLine(attachment.Name);
    FileAttachment fileAttachment = attachment as FileAttachment;
    string imagename = s + "-" + System.DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".jpg";

    /* download attachment to folder */
    fileAttachment.Load(imageLocation + "\\Images\\" + imagename);
}

我没有测试上述内容,但这只适用于任何jpeg
文件附件

我将代码更改为以下内容,但每次它都会在error item not Found.Console.WriteLine(attachment.Name)的.load语句中抛出一个错误;字符串sID=attachment.ContentId;sType=sType.Replace(“image/”,“”);字符串sFilename=attachment.Name;字符串SPATPlusFileName=Directory.GetCurrentDirectory()+“\\”+sFilename;((FileAttachment)attachment).Load(sFilename);
foreach (var attachment in mail.Attachments.Where(a => a is FileAttachment && a.ContentType == "image/jpeg"))
{
    Console.WriteLine(attachment.Name);
    FileAttachment fileAttachment = attachment as FileAttachment;
    string imagename = s + "-" + System.DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".jpg";

    /* download attachment to folder */
    fileAttachment.Load(imageLocation + "\\Images\\" + imagename);
}