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