Convert HTML to MHT File in C#

MHT is a webpage archive format that is commonly used to archive online content on a local machine. You can save a webpage to a single file containing all linked resources like images, flash animations, CSS, etc. as an MHT file. In some situations, you may need to convert an HTML file to MHT format. In accordance with such requirements, this article discusses how to convert HTML to MHT format programmatically in C#.

HTML to MHT File Converter – C# API Installation

Aspose.HTML for .NET API supports working with several popular file formats like HTML, MHTML, EPUB, etc. You can easily access the API by downloading its DLL files from the New Releases section or with the NuGet installation command below:

PM> Install-Package Aspose.Html

Convert HTML to MHT or MHTML in C#

You can convert an HTML file to an MHT or MHTML file with the following steps:

  1. Initialize an instance of the MHTMLSaveOptions class.
  2. Save the output file after converting the HTML file with the ConvertHTML method.

The following code snippet demonstrates how to convert an HTML file to an MHT or MHTML file programmatically in C#:

Convert HTML to MHT with Advanced Options in C#

There are several properties that improvise the HTML to MHT or MHTML file conversion. The MHTMLSaveOptions class lets you work with the restrictions to handle pages or URLs as well as the depth of pages. You need to follow the steps below to convert HTML to MHT or MHTML file:

  1. Create an object of the MHTMLSaveOptions class.
  2. Set different properties for the output file.
  3. Convert the HTML to MHT file with ConvertHTML method.

The  following code snippet shows how to convert an HTML file to MHT format in C#:

Explore Aspose.HTML for .NET API

You can visit the documentation section to explore other features offered by the API.

Get Free License

You can evaluate the API without any evaluation limitations by requesting a free temporary license.

Conclusion

In this article, you have understood how to convert an HTML to MHT or MHTML file programmatically in C#. In case of any inquiries, please write to us at the forum.

See Also

Convert MHT or MHTML to Word DOCX File in C#