question

RichardLoba-6868 avatar image
0 Votes"
RichardLoba-6868 asked RichardLoba-6868 commented

Exchange attachment size is incorrect

Hello,

Code that used to work a few years ago is now failing.
I'm reading in an email through EWS, getting the attachment and saving it to a SQL database.

The problem is for some reason the file size does not match the content size, as you can see below.
The content size is correct, and can be saved to the DB.
I have two SQL records, one saved by getting from disk, the other from EWS, and they are exactly the same.
Saving the incorrect file size does not allow me to load in the attachment into my ui, because the file size is incorrect.

This following example is an Excel 22KB attachment

As you can see the content size is 22016, whereas the attachment 'size' property is incorrectly set to 22352


Content {byte[22016]} byte[]
Size 22352 int

itItem.Attachments[i] {Microsoft.Exchange.WebServices.Data.FileAttachment}
Microsoft.Exchange.WebServices.Data.Attachment
{Microsoft.Exchange.WebServices.Data.FileAttachment}
Content {byte[22016]} byte[]
ContentId "B69182D944497F49B0EE99CBA1B215CA@namprd14.prod.outlook.com" string
ContentLocation null string
ContentType "application/vnd.ms-excel" string
FileName null string
IsContactPhoto false bool
IsInline false bool
LastModifiedTime {7/22/2021 2:07:51 PM} System.DateTime
Name "Attach Excel.xls" string
Size 22352 i nt

Id "AQMkADAwATM0MDAAMS0yZWIzLTVjMmItMDACLTAwCgBGAAAD8QDBv3KkD0OTTIYQjKXPLgcAhjZRaTuzP0qwyGWN/oN3kwAAAgEMAAAAhjZRaTuzP0qwyGWN/oN3kwAAAQEt4AAAAAESABAAxUotxNfcTk4AiwCEWseJa6w=" string

Any ideas what's up?

Thank you,

office-exchange-server-deploymentoffice-exchange-server-dev
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @RichardLoba-6868 ,

Thanks for asking questions in Q&A platform!

Basically we discuss Exchange general questions in office-exchange-server-deployment, the EWS and SQL tech are not included. I added the office-exchange-server-dev tag for your question, and sincerely hope your issue could be resolved soon.

Best regards,
Lou

0 Votes 0 ·

1 Answer

GlenScales-6756 avatar image
1 Vote"
GlenScales-6756 answered RichardLoba-6868 commented

The sizes you are getting are correct based on the property specification which is https://technet.microsoft.com/en-us/library/cc839742(v=office.14) (this is the property that EWS is exposing in this instance).

This is not to meant to reflect the exact size of the attachment but the size of the attachment + its properties which more accurately reflects the size it consumes in the Information store. As the spec also states "This property can be used to check the approximate size of the attachment before performing a remote transfer by modem and to display progress indicators when saving the attachment to disk"

This is not something that hasn't changed recently (as per the docs) its always been that way the one thing that has changed is reference (cloudy) attachments

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for the information Glen. Interesting about it not using the attachment size property the way I was thinking. My first EWS web app was for Microsoft around 2014 or 15. I was using that size variable the same way. I would open the email, pull the attachment, save it and the size to SQL server and was able to then retrieve and show the attachment. I’ll have to play with it, if what you say is true then I must have some other factor in my code.
Again, thank you for the information Glen, it is greatly appreciated.

0 Votes 0 ·