I am creating word document as memory stream and I am to send it as email attachment. But when I create attachment from memory stream, document in email is empty. Here is my commented code, pleace for help:
' create mail message
Dim mail As New MailMessage()
mail.From = New MailAddress(sMailFrom)
mail.To.Add(sMailTo)
mail.Subject = "Test email"
mail.Body = "See for attachments"
' create (open) document from template
Dim doc As New Document()
doc.LoadFromFile(sFileName, FileFormat.Docx)
.....
' Test save to file - DOCX is correct
doc.SaveToFile("c:\temp\test.docx", FileFormat.Docx)
' Save file to the stream
Dim ms as New System.IO.MemoryStream
doc.SaveToStream(ms, FileFormat.Docx)
' create attachment from stream
mail.Attachments.Add(New Attachment(ms, "Licence.docx", "text/msword"))
'send the message
Dim smtp As New SmtpClient
smtp.Send(mail)
Attachment in mail message is empty, only 105 B