Question

I'm trying to write a simple service that will take ItemAttachments and move them to an arbitrary Microsoft.Exchange.WebServices.Data.Folder. Can this be done? I'm using Exchange 2010 SP2.

The following code generates a System.InvalidOperationException: "This operation isn't supported on attachments."

private void ProcessItem(ItemId id, Folder folder) 
{
    Item envelope = Item.Bind(_ExchangeService, id, new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.Attachments));
    if (envelope.HasAttachments && envelope.Attachments[0] is ItemAttachment) 
    {
        ItemAttachment attachedItem = envelope.Attachments[0] as ItemAttachment;  // always only one
        attachedItem.Load(new PropertySet(ItemSchema.ItemClass));
        Item itemToMove = attachedItem.Item;
        try 
        {
            itemToMove.Move(folder.Id); //this is the bad boy!
        } 
        catch (Exception ex) 
        {
            Console.WriteLine(ex.ToString());
            throw;
        }
    }
}

Any suggestions or help would be much appreciated.

Was it helpful?

Solution

This was answered by Glen Scales on the Exchange TechNet Forum.

"That won't work because Move, Copy are only valid operations for real store Items. An ItemAttachment is still an attachment so the only valid operations that you can perform are those assoicated with attachments.

The only real workaround with EWS is if the ItemAttachment is an email Message is you could grab the MimeContent of the ItemAttachment and then upload that to other folder (you would loose some fidelity here) or create a new item and copy the Item properties property by property. Otherwise this is something you should use MAPI to do, even then you will need to save the Item Attachment as a MSG file and then upload it to the folder you want."

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top