Saving URLs to MHTML via .NET

I just posted another CodeProject article, Convert any URL to a MHTML archive using native .NET code. The title is a bit misleading; using my class, you can actually convert any URL to one of four formats in a single line of code:

  • Web Page, complete (HTML plus files in subfolder)
  • Web Archive, single file (MHTML only)
  • Web Page, HTML only (HTML only)
  • Text File (TXT only)
This mimics the File | Save As menu in Internet Explorer as closely as I could get it to. It's pretty darn close, and quite handy. We are using IE as a basic reporting engine, and it's a lot easier to email someone a report-- or store it in a document management system-- when you have a single MHTML file!

I knew IE had some crazy way of saving a complete web page as a single file, but I was as surprised as anyone else to find that IE's "Web Archive" save option is based on an actual internet standard: RFC standard 2557, compliant Multipart MIME Message (MHTML web archive). As I mentioned a few months ago, this should work in Firefox, too..