Hopefully a very simple one. I migrated an application to .net-core
3.1 from .net
framework 4.7 that uses EWS
. Other than making numerous interactions Async all seems to be working fine without any change. Apart from downloading attachments from the email. Whilst debugging and using the object examiner the FileAttachment
object exists and the object properties/size look exactly what I expect. The FileAttachment
.Load
(string outputPath) creates a file, however, the file has 0KB content size. So the shell has been created but no data has been streamed into it. Probably I'm missing something obvious but the obvious is escaping me. Tried using the stream and output path methods, the same result. The function works fine still in the .net
framework version. Any ideas very greatly appreciated?
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);
}
This github comment fixed it for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With