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



  • Edited by Halomoan K Wednesday, July 08, 2015 7:54 AM
July 8th, 2015 7:50am

Hi Glen

Sorry for my late reply, just be back from my vacation. 

You are right, our Exchange Server had never been touched for patch update since the 1st installation. I will bring this to our Exchange Server engineer for them to plan to update the server. Hopefully it will works after the patches update. I'll update you.

Thanks,
Halomoan

Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 8:34pm

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

Other recent topics Other recent topics