2015-11-06 35 views
0

,以便檢索電子郵件,我使用EWS從EWS附件,但是當我要檢索的附件我呼籲每個以下功能:檢索一次使用EWS託管API 2.0

fileAttachment.Load(); 

每次我這樣做,它都會去服務器。是否有可能一次檢索所有附件?另外,是否有可能檢索幾個郵件的所有附件?

回答

1

ExchangeService對象有一個GetAttachments方法,它基本上允許您執行批量GetAttachment請求。所以,如果你想一次你需要做這樣的事情(第一次調用loadpropertiesforitems這確實一批的GetItem得到AttachmentIds)

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

乾杯 格倫加載在幾個消息中的附件

+0

我只好裝2.2爲此,但我會把它作爲答案。 –

相關問題