Exchange attachment size is incorrect

Richard Loba 6 Reputation points
2021-07-25T20:16:34.517+00:00

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,

Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
507 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,347 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Glen Scales 4,431 Reputation points
    2021-07-27T01:23:19.08+00:00

    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 person found this answer helpful.