title: Why extract attacment content is always null while writing stream?
body: <p>i know that it is simple question but i could not find solution. i have been trying to extract attachments from email, after that i will write to filestream for saving file any director. But my fileAttachment.Content is always null. How to save inside of my directory from email adresses?</p>
  
  <pre><code>public static void ExtractAttachment(string targetDir)
  {
  
      SearchFilter.IsEqualTo ffrom = new SearchFilter.IsEqualTo(EmailMessageSchema.From, "xxx@yyyy.com.tr");
      SearchFilter.ContainsSubstring fsubject = new SearchFilter.ContainsSubstring(ItemSchema.Subject, "yyyyyyyy", ContainmentMode.Substring, ComparisonMode.IgnoreCaseAndNonSpacingCharacters);
      SearchFilter.IsEqualTo fattach = new SearchFilter.IsEqualTo(EmailMessageSchema.HasAttachments, true);
      SearchFilter.IsGreaterThanOrEqualTo fdate = new SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeReceived, DateTime.Now.Date);
      SearchFilter.SearchFilterCollection mfilter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, fdate, ffrom, fattach, fsubject);
  
      ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
      service.Credentials = new WebCredentials(ConfigurationManager.AppSettings["Username"], ConfigurationManager.AppSettings["Password"]);
      service.Url = new Uri(ConfigurationManager.AppSettings["ExchangeService"]);
      ItemView view = new ItemView(24);
      view.PropertySet = new PropertySet(ItemSchema.DateTimeReceived, ItemSchema.Subject, EmailMessageSchema.HasAttachments, EmailMessageSchema.From);
      view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);
      view.Traversal = ItemTraversal.Shallow;
      FindItemsResults&lt;Item&gt; searchitem = service.FindItems(WellKnownFolderName.Inbox, mfilter, view);
      if (searchitem.TotalCount &gt; 0)
      {
          for (int i = 0; i &lt; searchitem.Items.Count; i++)
          {
              Console.WriteLine("loop is working");
  
              searchitem.Items[i].Load(PropertySet.FirstClassProperties);
  
              foreach (Attachment part in searchitem.Items[i].Attachments)
              {
                  if (part is FileAttachment &amp;&amp; string.IsNullOrEmpty(part.Name) == false &amp;&amp; Path.GetExtension(part.Name).Equals(".txt", StringComparison.InvariantCultureIgnoreCase))
                  {
  
                      using (MemoryStream ms = new MemoryStream())
                      {
                          FileAttachment fileAttachment = part as FileAttachment;
                          fileAttachment.Load(ms);
                          ms.Position = 0;
  
                          string fname = Path.Combine(targetDir, fileAttachment.Name);
                          string fdir = Path.GetDirectoryName(fname);
                          if (!Directory.Exists(fdir)) Directory.CreateDirectory(fdir);
  
                          using (FileStream fstream = new FileStream(fname, FileMode.Create))
                          {
                              fstream.Write(fileAttachment.Content, 0, fileAttachment.Content.Length);
                          }
  
                      }
                  }
                  break;
              }
          }
      }
  
  }
  </code></pre>