Search code examples
c#mhtml

Reading .mhtml file from C# program


Is it possible to read .mhtml files from C# program ? or can it be convert to other file format(.txt) so that C# program able to read the content inside. Thank you.


Solution

  • You can refer to the library HtmlAgilityPack for this. It's quite simple to use.

    Here is the link to download: https://www.nuget.org/packages/HtmlAgilityPack/

    https://html-agility-pack.net/from-file

    Here is a sample. Hope to help, my friend :))

    string path = @"C:\Users\tdmanh\Desktop\HtmlAgilityPack.mhtml";
                var doc = new HtmlDocument();
                doc.Load(path);
                var node = doc.DocumentNode.SelectSingleNode("//body");
    
                Console.WriteLine(node.OuterHtml);