EWS 2.2 - The attachment could not be opened

Hi All

I'm connecting to the Exchange Server 2010 SP2 from my C# application with EWS version 2.2 to download a big image attachment in my calendar item. The image size is 5,976,794 bytes as reported by fileAtt.Size property. The application throws exception:

Microsoft.Exchange.WebServices.Data.ServiceResponseException: The attachment could not be opened.

at

Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNecessary()

at

Microsoft.Exchange.WebServices.Data.ServiceResponse.ThrowIfNecessary()

at

Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()

at

Microsoft.Exchange.WebServices.Data.ExchangeService.InternalGetAttachments(IEnumerable`1 attachments, Nullable`1 bodyType,IEnumerable`1 additionalProperties, ServiceErrorHandling errorHandling)

at

Microsoft.Exchange.WebServices.Data.ExchangeService.GetAttachment(Attachment attachment,Nullable `1 bodyType, IENumerable`1 additionalProperties)

at

Microsoft.Exchange.WebServices.Data.Attachment.InternalLoad(Nullable`1 bodyType, IENumerable`1 addtionalProperties)

at Microsoft.Exchange.WebServices.Data.Attachment.Load()

Here is my code to download the attachment:

service.LoadPropertiesForItems(items, PropertySet.FirstClassProperties);

foreach (Appointment a in appointments) {

string htmlBody = a.Body.Text;

foreach(Attachment att in a.Attachments) {

if (att is FileAttachment) {

FileAttachment fileAtt = att as FileAttachment;

FileStream theStream = new FileStream(String.Format(@"ANP\{0}", att.ContentId ), FileMode.OpenOrCreate, FileAccess.ReadWrite);

fileAtt.Load(theStream);

       theStream.Close();

       theStream.Dispose();

}

}

}

The exception is triggered by this code line: fileAtt.Load(theStream);

Do I miss something ? If the attachment is < 5 Mb, the codes run very well and I can download the attachment.

Please help.

Thank you so much.

Halomoan



July 8th, 2015 3:52am

Can you open the attachment in OWA ? I would also try using the EWSEditor https://ewseditor.codeplex.com/ . If you still get an error post the SOAP response you get from the server  (you can get this by either enabling tracing in your code or the EWSEditor has a request log the exception your getting isn't really that helpful).

Cheers
Glen

Free Windows Admin Tool Kit Click here and download it now
July 9th, 2015 12:20am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics