1

我正試圖編寫一個簡單的服務,它將採用ItemAttachments並將它們移動到任意Microsoft.Exchange.WebServices.Data.Folder。這可以做到嗎?我正在使用Exchange 2010 SP2。如何使用EWS託管API將ItemAttachments移動到文件夾2

下面的代碼生成一個System.InvalidOperationException:「此操作不支持附件

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; 
     } 
    } 
} 

任何建議或幫助,將不勝感激。

回答

1

這是由格倫回答秤上Exchange TechNet Forum

「這不會起作用,因爲移動,複製只對實體店經營項目有效運作。一個ItemAttachment仍然是一個附件,以便您可以執行的唯一有效的操作是那些帶有附件的assoicated。

唯一與EWS真正的解決方法是,如果ItemAttachment是電子郵件消息是你可以抓住ItemAttachment的MimeContent,然後將其上傳到其他文件夾(這裏你會失去一些保真度)或創建一個新項目並按屬性複製項目屬性屬性。否則,這是您應該使用MAPI執行的操作,即使您需要將項目附件另存爲MSG文件,然後將其上傳到您想要的文件夾中。「

相關問題