希望是一个非常简单的。我将应用程序迁移到 .net-core
3.1 来自 .net
使用 EWS
的框架 4.7 .除了进行大量交互异步之外,所有似乎都可以正常工作而无需任何更改。除了从电子邮件下载附件。在调试和使用对象检查器时,FileAttachment
对象存在并且对象属性/大小看起来正是我所期望的。 FileAttachment
. Load
(string outputPath) 创建一个文件,但是,该文件的内容大小为 0KB。所以 shell 已经创建,但没有数据流入其中。可能我错过了一些明显的东西,但明显的东西正在逃避我。尝试使用流和输出路径方法,结果相同。该功能在 .net
中仍然正常工作框架版本。任何想法非常感谢?
foreach (EmailMessage email in orderedList)
{
EmailMessage message = await EmailMessage.Bind(_service, email.Id, new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.Attachments));
if (email.HasAttachments)
{
foreach (Attachment attachment in message.Attachments)
{
bool getFile = false;
if (attachment is FileAttachment)
{
FileAttachment fileAttachment = attachment as FileAttachment;
if (!string.IsNullOrEmpty(filename) && fileAttachment.Name.StartsWith(filename))
{
getFile = true;
}
else if (string.IsNullOrEmpty(filename))
{
getFile = true;
}
if (getFile)
{
//var response = await fileAttachment.Load();
//FileStream theStream = new FileStream(outputDirectory + fileAttachment.Name, FileMode.Create, FileAccess.ReadWrite);
//fileAttachment.Load(theStream);
//theStream.Close();
//theStream.Dispose();
fileAttachment.Load(outputDirectory + fileAttachment.Name);
message.IsRead = true;
await message.Update(ConflictResolutionMode.AlwaysOverwrite, true);
filepaths.Add(outputDirectory + fileAttachment.Name);
}
}
}
}
}
最佳答案
https://github.com/sherlock1982/ews-managed-api/issues/40
var f1 = await fileAttachment.Load();
if (f1 != null)
{
FileAttachment loaded = f1.First().Attachment as FileAttachment;
File.WriteAllBytes(outputDirectory + fileAttachment.Name, loaded.Content);
}
这个 github 评论为我修复了它
关于.Net Core 3.1 迁移后 C# Exchange Web 服务附件保存不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61630559/