3

I need to save ItemAttachments retrieved using EWS API but I don't know file extension of all the different item types.I could only manage to get the extension of item of type EmailMessage and Contact. Here is the code.

if (attachment is ItemAttachment)
{
    var itemAttachment = attachment as ItemAttachment;

    itemAttachment.Load(new PropertySet(ItemSchema.MimeContent));

    var fileExtension = "";

    if (itemAttachment.Item is EmailMessage)
    {
        fileExtension = ".eml";
    }
    else if (itemAttachment.Item is PostItem)
    {
        fileExtension =??  
    }
    else if (itemAttachment.Item is Contact)
    {
        fileExtension = ".vcf";
    }
    else if (itemAttachment.Item is ContactGroup)
    {
        fileExtension =??
    }
    else if (itemAttachment.Item is Appointment)
    {
        fileExtension = ??
    }
    else if (itemAttachment.Item is Task)
    {
        fileExtension = ??
    }
}

Can somebody tell me what are the file extensions of rest of the items??

domdomcodecode
  • 2,355
  • 4
  • 19
  • 27
Sameer
  • 3,124
  • 5
  • 30
  • 57

1 Answers1

1

You have the MIME content of EmailMessage and Contact items correct. The MIME content of an Appointment represents an .ics file (note that you will not get the full-representation, particularly if it is an appointment with attendees). The MIME content of the PostItem, ContactGroup, and the Task items do not represent a particular file type that I know of. You will need to parse the MIME stream (or request the properties on each item), and create a file from that. For example, you can parse the Task properties and create a vTodo file. I suggest you look for some sort of standard file type for ContactGroup (distribution list) and PostItem and parse the results into that file type.

In general, I suggest that you don't use the MIME content since it may not have all the properties you need. To approach full-fidelity and for better performance (from the service), request the properties you need on the attachments, and parse the results into the end file type.

Community
  • 1
  • 1
Michael Mainer
  • 3,387
  • 1
  • 13
  • 32
  • Thanks Michael!!!. Yes I have the mime content of EmailMessage and Contact and I am saving the mime as .eml and .vcf respectively. And, I can see all the things intact when i open the saved mime content. Do you have any documentation where in you have the properties missing out from mime is listed ? I wish I could simply treat itemattachment as file attachment and simply download the file in some standard format without getting concerned about mime parsing/requesting specific properties and all . It's so awkward. I wonder why it has to be this way. – Sameer Apr 08 '14 at 04:19
  • @Mokchhya - You are welcome. No, we don't have any documentation on which properties are returned (or not) in the MIME stream. We try to discourage the use of the MIME stream since there is server cost for converting the database properties in the MIME stream. The MIME stream is exposed for backwards compatibility. We try to promote that implementers only request the properties they need, not the entire property bag. Can you tell me what you are trying to accomplish? – Michael Mainer Apr 08 '14 at 16:57
  • 1
    I need to grab the attachment as it is and save it as a file. – Sameer Apr 09 '14 at 04:01