2016-07-07 98 views
0

是否有可能直接獲取EWS Managed API的附件,而無需首先獲取其包含的EmailMessage?如何使用EWS託管API通過ID獲取附件?

喜歡的東西:

FileAttachment attach = FileAttachment.Bind(ewsService, attachId); 

我找不到這方面的任何方法。

回答

1

可以使用ExchangeService類https://msdn.microsoft.com/en-us/library/office/dn600509(v=exchg.80).aspx的GetAttachments方法,這可以讓你批一個或多個GetAttachment請求在一起,例如:

 FindItemsResults<Item> fItems = service.FindItems(WellKnownFolderName.Inbox,new ItemView(10)); 
    PropertySet psSet = new PropertySet(BasePropertySet.FirstClassProperties); 
    service.LoadPropertiesForItems(fItems.Items, psSet); 
    List<Attachment> atAttachmentsList = new List<Attachment>(); 
    foreach(Item ibItem in fItems.Items){ 
     foreach(Attachment at in ibItem.Attachments){ 
      atAttachmentsList.Add(at); 
     } 
    } 
    ServiceResponseCollection<GetAttachmentResponse> gaResponses = service.GetAttachments(atAttachmentsList.ToArray(), BodyType.HTML, null); 
    foreach (GetAttachmentResponse gaResp in gaResponses) 
    { 
     if (gaResp.Result == ServiceResult.Success) 
     { 
      if (gaResp.Attachment is FileAttachment) 
      { 
       Console.WriteLine("File Attachment"); 
      } 
      if (gaResp.Attachment is ItemAttachment) 
      { 
       Console.WriteLine("Item Attachment"); 
      } 
     } 
    } 
相關問題