title: How to download specific file attachments on EWS API
body: <p>this is what I have so far, the thing is with this code i can download all of the attachments found in the message, but what i really need is to download two specific file extension attachment (.PDF  and .XML, IE), any tip will be very grateful:</p>
  
  <pre><code>static void Main(string[] args)
      {
          try
          {
              ExchangeService service = new      ExchangeService(ExchangeVersion.Exchange2010_SP2);
              service.Credentials = new NetworkCredential("USR", "PWD", "domain");
              service.AutodiscoverUrl("someone@example.com");
  
              FindItemsResults&lt;Item&gt; findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(int.MaxValue));
              Console.WriteLine("Found " + findResults.TotalCount + " Messages");
  
                  if (findResults != null &amp;&amp; findResults.Items != null &amp;&amp; findResults.Items.Count &gt; 0)
                      foreach (Item item in findResults.Items)
  
                      {
                          EmailMessage message = EmailMessage.Bind(service, item.Id, new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments, ItemSchema.HasAttachments));
                          foreach (Attachment attachment in message.Attachments)
                          {
                              if (attachment is FileAttachment)
                              if (attachment.Name.Contains(".xml"))
                              {
                                  FileAttachment fileAttachment = attachment as FileAttachment;
                                  fileAttachment.Load("c:\\folder\\" + fileAttachment.Name);
                                  Console.WriteLine("Attachment name: " + fileAttachment.Name);
                              }
                          }
                          Console.WriteLine(item.Subject);
                      }
                  else
                      Console.WriteLine("No messages");
          }
          catch (Exception e)
          {
  
              Console.WriteLine(e.Message);
          }
      }
  </code></pre>