title: Email Attachment from memory stream is coming as blank in C#
body: <p>I am able to send an attachment in a mail but the attachment content is blank and size is being shown as 0 bytes.</p>
  
  <p>After doing some search over the internet found that we need to reset the memory stream position to 0 in order to start from start.</p>
  
  <p>I tried that as well but it seems it is not working. Can you please help?</p>
  
  <p>Please find below my code snippet:</p>
  
  <p>NOTE: I am able to save the workbook and Data is present in the saved workbook.</p>
  
  <pre><code>        MemoryStream memoryStream = new MemoryStream();
  
          StreamWriter writer = new StreamWriter(memoryStream);
          writer.Write(xlWorkbook);
          writer.Flush();
          memoryStream.Position = 0;
          MailMessage mail = new MailMessage();
          SmtpClient SmtpServer = new SmtpClient("smtpclient");
          mail.From = new MailAddress("from@gmail.com");
          mail.To.Add("To@gmail.com");
          mail.Subject = "Entry";
          mail.Body = "Hello, PFA ";
          System.Net.Mail.Attachment attachment;
  
          attachment = new System.Net.Mail.Attachment(memoryStream,"xls");
          attachment.ContentDisposition.FileName = "Input" + DateTime.Now.ToString("yyyyMMdd_hhss") + ".xls";
          mail.Attachments.Add(attachment);
          SmtpServer.Port = 465;
          SmtpServer.UseDefaultCredentials = false;
          SmtpServer.Credentials = new System.Net.NetworkCredential("Username", "password");
          SmtpServer.EnableSsl = true;
          SmtpServer.Send(mail);
          writer.Dispose();
  </code></pre>