EWS Attachment Name Incorrect

We are encountering an issue with EWS 2.2 Managed API(and previous versions) and attachment names.  EWS exposes two potential fields for an attachment name.  Name, and FileName.  In our findings, Name can sometimes report the same file name we see in mail clients (such as Outlook), and FileName is always black (Nothing in VB.NET).

The XML request and responses are output from the "ExchangeService.TraceEnabled = True" and "ExchangeService.TraceFlags = TraceFlags.All" options.

XML request example:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2010_SP2" />
  </soap:Header>
  <soap:Body>
    <m:GetItem>
      <m:ItemShape>
        <t:BaseShape>IdOnly</t:BaseShape>
        <t:AdditionalProperties>
          <t:FieldURI FieldURI="item:Attachments" />
        </t:AdditionalProperties>
      </m:ItemShape>
      <m:ItemIds>
        <t:ItemId Id="biglongItemId" />
      </m:ItemIds>
    </m:GetItem>
  </soap:Body>
</soap:Envelope>


EWS XML response:

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
  <h:ServerVersionInfo MajorVersion="14" MinorVersion="3" MajorBuildNumber="195" MinorBuildNumber="1" Version="Exchange2010_SP2" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <m:GetItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
    <m:ResponseMessages>
      <m:GetItemResponseMessage ResponseClass="Success">
        <m:ResponseCode>NoError</m:ResponseCode>
        <m:Items>
          <t:Message>
            <t:ItemId Id="biglongItemId" ChangeKey="CQAAABYAAAB6Lqmbg0p2SpXlhlOVcY4TAAAnDxiX" />
            <t:Attachments>
              <t:FileAttachment>
                <t:AttachmentId Id="biglongAttachmentId" />
                <t:Name>body.csv</t:Name>
                <t:ContentType>text/plain</t:ContentType>
                <t:ContentId>{6981D03B-2EBD-4F8F-BF8D-61424696F792}</t:ContentId>
                <t:Size>135</t:Size>
                <t:LastModifiedTime>2014-01-03T02:13:44</t:LastModifiedTime>
                <t:IsInline>false</t:IsInline>
                <t:IsContactPhoto>false</t:IsContactPhoto>
              </t:FileAttachment>
            </t:Attachments>
          </t:Message>
        </m:Items>
      </m:GetItemResponseMessage>
    </m:ResponseMessages>
  </m:GetItemResponse>
</s:Body>
</s:Envelope>

In the example above, Name is body.csv.  FileName as nothing.  In Outlook, the attachment file name is "CUSTOMER.CSV".

I have confirmed with the sender that file attachment file is named "CUSTOMER.CSV".

Can anyone provide some insight into why EWS reports a file name that is not what was provided by the sender?

Thanks much in advance.

February 3rd, 2015 2:52pm

The FileName property is a Managed API property used to create attachments. You set this property on a FileAttachment object when creating a new attachment, and the API will load the contents from the file. It has no meaning when you are retrieving attachments from the server. When retrieving, the only information you have is the Name.

In the Exchange store, there are a number of properties on attachments related to the name. For example, there is PidTagDisplayName, PidTagAttachFileName, and PidTagAttachLongFileName. EWS uses PidTagDisplayName, which is usually the same as PidTagAttachLongFileName. However, it *can* be different. Outlook appears to use PidTagAttachLongFileName in their UI. So most likely for this message, the PidTagDisplayName value is "body.csv", and PidTagAttachLongFileName is "CUSTOMER.CSV". You can check with a MAPI viewer (MFCMapi or OutlookSpy).

Free Windows Admin Tool Kit Click here and download it now
February 3rd, 2015 5:13pm

Thank you for the explanation.

I guess my question would be is PidTagAttachLongFileName exposed in EWS?  I cannot find any documentation on that.

It seems that should be the reported "name" as it is the file name specified by the sender (especially if you are only exposing one property for attachment name).

We would prefer to use the EWS managed API than MAPI.

February 4th, 2015 12:16am

I can forward your feedback to our developers. PidTagAttachLongFileName isn't exposed by EWS unfortunately. In most cases the two values should match. It's actually not straightforward to change the display name using Outlook or OWA.

Free Windows Admin Tool Kit Click here and download it now
February 5th, 2015 10:40am

A forward to the devs would be great, and thank you.  It is very much appreciated.

February 5th, 2015 3:19pm

Hi guys,

I am currently experiencing the same problem here. I am using EWS API to access email items and their attachments. Sometimes the .Name property returns correct filename but sometimes it just return body.fileextension. Do we have a fix or a work around for this issue. It is very critical at the moment for us as it affects our invoicing system.

Thanks.

Doug

Free Windows Admin Tool Kit Click here and download it now
July 2nd, 2015 2:12am

We are having similar issues, when using a third party software the PidTagAttachLongFileName is getting mismatched from the PidAttachFileName. If I could get the long file name from EWS that would make a world of a difference.
August 12th, 2015 12:15pm

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

Other recent topics Other recent topics