2013-02-01 33 views
4

是否可以保存ItemAttachment?對於FileAttachment我們使用以下EWS託管API代碼來保存,如何使用EWS託管API保存ItemAttachments

if(attachment is FileAttachment) 
    { 
     FileAttachment fAttachment = new FileAttachment(); 
     fAttachment.Load("D:\\Stream" + fAttachment.Name); 
    } 

什麼有關ItemAttachment?我們如何才能將ItemAttachment像這樣保存在指定的文件中?

+0

什麼Microsoft.Exchange版本.WebServices.dll你使用? –

回答

6

當然,這並不是一件緊迫的事情,但我想我會分享任何在未來會像我一樣磕磕絆絆的人。

對於您需要加載MimeContent該項目ItemAttachments,那麼你可以簡單地寫在文件/輸出[「的.eml」,「味精」]:

if (attachment is FileAttachment) 
{ 
    FileAttachment fileAttachment = attachment as FileAttachment; 

    // Load attachment contents into a file. 
    fileAttachment.Load(<file path>); 
} 
else // Attachment is an ItemAttachment (Email) 
{ 
    ItemAttachment itemAttachment = attachment as ItemAttachment; 

    // Load Item with additionalProperties of MimeContent 
    itemAttachment.Load(EmailMessageSchema.MimeContent); 

    // MimeContent.Content will give you the byte[] for the ItemAttachment 
    // Now all you have to do is write the byte[] to a file 
    File.WriteAllBytes(<file path>, itemAttachment.Item.MimeContent.Content); 
} 
+0

你使用什麼版本的Microsoft.Exchange.WebServices.dll? –

+0

抱歉,延遲。我正在使用Microsoft EWS託管API 2.0: 信息: 庫的直接鏈接:

+0

沒問題。這個'itemAttachment.Load(EmailMessageSchema.MimeContent);'我一直想念的東西。 –

相關問題