none
EWS: How to get attachment(s) full info for a CalendarItem? RRS feed

  • Question

  • I'm getting a CalendarItem with attachments using such SOAP request against Office 365:

    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
      <soap:Header>
        <t:RequestServerVersion Version="Exchange2007_SP1"/>
      </soap:Header>
      <soap:Body>
        <GetItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
          <ItemShape>
            <t:BaseShape>AllProperties</t:BaseShape>
            <t:AdditionalProperties>
              <t:FieldURI FieldURI="item:Attachments" />
            </t:AdditionalProperties>
          </ItemShape>
          <ItemIds>
            <t:ItemId Id="..." ChangeKey="..."/>
          </ItemIds>
        </GetItem>
      </soap:Body>
    </soap:Envelope>

    And I get a list of attachments with limited info in the response message:

    <t:Attachments>
      <t:FileAttachment>
        <t:AttachmentId Id="..."/>
        <t:Name>20140110_055901_NR.MP4</t:Name>
      </t:FileAttachment>
      <t:ItemAttachment>
        <t:AttachmentId Id="..."/>
        <t:Name>hidden discussion topic</t:Name>
      </t:ItemAttachment>
    </t:Attachments>

    But where are ContentType and ContentId properties under the ItemAttachment?? You normally get them when you get an Email item with list of attachments, e.g.:

    <t:FileAttachment>
      <t:AttachmentId Id="..."/>
      <t:Name>test.txt</t:Name>
      <t:ContentType>text/plain</t:ContentType>
      <t:ContentId>45798FE9C0BFEC40BD46E31E03DEE9AF@namprd05.prod.outlook.com</t:ContentId>
    </t:FileAttachment>

    The CalendarItem HTML body can contain inline references to attachments:

    <a href="cid:D44D196860052BCAF2ED99715B47485F516D1531@1">20140110_055901_NR.MP4</a>

    But I don't see any way to find out the ContentId for an attachment in a CalendarItem.

    Is there any known workaround?

    -----------------------------

    UPDATE

    If you get MIME of the CalendarItem, you can fetch ContentId from ATTACH header(s), e.g.:

    ATTACH:CID:D44D196860052BCAF2ED99715B47485F516D1531@namprd05.prod.outlook.com

    And I assume that "@1" in the HTML href is the alias for "@namprd05.prod.outlook.com".

    But is the order of attachments in MIME and SOAP response the same?

    Any other foolproof solutions?


    • Edited by sergiis Tuesday, February 23, 2016 12:29 AM
    Tuesday, February 23, 2016 12:06 AM

Answers

  • The Body format for an Appointment if its created using Outlook or OWA against an Exchange server will be RTF and no ContentId will be set on the Attachment. When you access the Body as HTML the store will do a On the fly conversion from RTF to HTML (you can see this if you look at the Meta information in the HTML returned you should see something like

    <meta name="Generator" content="Microsoft Exchange Server">
    <!-- converted from rtf -->
    So the number of the Cid you get will be generated by this process based on the order of attachments in the Item so to answer your question

    >?But is the order of attachments in MIME and SOAP response the same?

    Yes it should be but its not a static value eg if changes where made to attachments or the Body on the Item then the Id will be regenerated the next time you attempt to access the body. You can easily test that

    My suggestion is that you treat attachments as a variable on the Item

    Cheers
    Glen

    • Marked as answer by sergiis Tuesday, February 23, 2016 8:39 PM
    Tuesday, February 23, 2016 3:24 AM

All replies

  • The Body format for an Appointment if its created using Outlook or OWA against an Exchange server will be RTF and no ContentId will be set on the Attachment. When you access the Body as HTML the store will do a On the fly conversion from RTF to HTML (you can see this if you look at the Meta information in the HTML returned you should see something like

    <meta name="Generator" content="Microsoft Exchange Server">
    <!-- converted from rtf -->
    So the number of the Cid you get will be generated by this process based on the order of attachments in the Item so to answer your question

    >?But is the order of attachments in MIME and SOAP response the same?

    Yes it should be but its not a static value eg if changes where made to attachments or the Body on the Item then the Id will be regenerated the next time you attempt to access the body. You can easily test that

    My suggestion is that you treat attachments as a variable on the Item

    Cheers
    Glen

    • Marked as answer by sergiis Tuesday, February 23, 2016 8:39 PM
    Tuesday, February 23, 2016 3:24 AM
  • Thanks Glen,

    Now It makes sense. If the internal format is RTF, attachments are inserted with the "\objattph" RTF tag which has no any reference ID, so the order of attachments matters.

    Tuesday, February 23, 2016 8:39 PM