Store mhtml in memoryStream

Hi,

How to store word document as a mhtml in memory stream…
and how to retrive html word document from memory stream and write in stream reader…
Pls provide the solution</div>


Thanks
Narendran

Hi Narendran,

Thanks for your inquiry. Please use following code example to export Word document into memory stream. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");
MemoryStream memoryStream = new MemoryStream();
doc.Save(memoryStream, SaveFormat.Mhtml);
memoryStream.Seek(0, SeekOrigin.Begin);
StreamReader streamReader = new StreamReader(memoryStream);

Thanks for reply,

In this above code How to retrive mhtml from memory stream

Pls tell me…

Thanks,
Narendran

Hi Narendran,

Thanks for your inquiry. Your query seems to be related to .NET API. If you want to save memory stream to disk, please use System.IO.File.WriteAllBytes method.

Could you please share some more detail about your query what exact you want to achieve using Aspose.Words? We will then provide you more information about your query.

Document doc = new Document(MyDir + "in.docx");
MemoryStream memoryStream = new MemoryStream();
doc.Save(memoryStream, SaveFormat.Mhtml);
memoryStream.Position = 0;
System.IO.File.WriteAllBytes(MyDir + @"output.mhtml", memoryStream.ToArray());

Thanks for reply,

I am trying to move html templates to body of the mail
How to write above code o link with body of the mail

Hi Narendran,


You can use Aspose.Email API to load the earlier saved Mhtml file in MailMessage object as shown in the sample code below. You can then use the MailMessage object to save it to disc in any supported format or send out the email using the API’s Smtp client. Please try the following code sample and let us know if we can be of any additional help to you in this regard.

Sample Code

MailMessage mail = MailMessage.Load(“output.mhtml”, new MhtmlLoadOptions());
mail.From = new MailAddress(“from@domain.com”);
mail.BodyEncoding = Encoding.UTF8;
mail.To.Add(“to@domain.com”);

SmtpClient client = new SmtpClient(“smtp.gmail.com”, 587, “username”, “password”);
client.Send(mail);