Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

EWS Managed API - Attachment content empty

$
0
0

Exchange 2010

Managed API 1.1

I'm grabbing attachments through EWS and serving them through a web service (WCF).

The code:

ownerId = ServiceFactory.MakeEmailAddress(ownerId);
var service = ServiceFactory.InstantiateService(ownerId);
var id = new AlternateId(IdFormat.HexEntryId, mailId, ownerId);
var convertedId = (AlternateId)service.ConvertId(id, IdFormat.EwsId);
var mail = EmailMessage.Bind(service, convertedId.UniqueId);
service.LoadPropertiesForItems(new[] { mail }, new PropertySet(ItemSchema.HasAttachments, ItemSchema.Attachments, ItemSchema.ParentFolderId));
var folder = Folder.Bind(service, mail.ParentFolderId);

var fileAttachment = (FileAttachment)mail.Attachments[int.Parse(index)];
fileAttachment.Load();
Response.ContentType = fileAttachment.ContentType;
Response.AddHeader("Content-Disposition","attachment; filename=\"{FILENAME}\""
                        .Replace("{FILENAME}", fileAttachment.Name.Replace("\"", "'")));
fileAttachment.Load(Response.OutputStream);

The problem is an attachment that seems like any other that returns 0 bytes in content and writes 0 bytes to the outputstream. I'm serving thousands of attachments without problems but this single one returns nothing. 3 other attachments in the same email message download without problems and if I look at the email in the exchange store the attachment is there and can be opened with outlook without problems. When stepping through the code I can see that the .Content property of the attachment (after calling Load()) is a byte[] with length 0.

Is there anything additional I need to look at to make sure the content of the email attachment is downloaded? Is there a known issue with certain types of attachments that I need to be aware of?

Regards, Högni



Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>