Converting a HTML file to a MHT Document
Converting a Url to a MHT Document
This sample is a short and simple example demonstrating the capability of
aspNetMHT to convert a URL to a MHT document.
[ C# ]
string url = "http://www.google.com";
//create a unique filename because .mht
//files are cached by IE so any changes made
//to the same file will not be reflected
//unless the IE cache is cleared
string filename
= "c:\\temp\\" + DateTime.Now.ToFileTime().ToString() + ".mht";
MHT m = new MHT( url );
//parse the HTML into it's MHT counterpart
m.Parse();
//save it to the filesystem
m.SaveToFile( filename );
[ VB.NET ]Dim url As String = "http://www.google.com"
'create a unique filename because .mht
'files are cached by IE so any changes made
'to the same file will not be reflected
'unless the IE cache is cleared
Dim filename As String
= "c:\temp\" + DateTime.Now.ToFileTime().ToString() + ".mht"
Dim m As New MHT(url)
'parse the HTML into it's MHT counterpart
m.Parse()
'save it to the filesystem
m.SaveToFile(filename)
Logging with aspNetMHT
This sample is a short and simple example demonstrating the capability of
aspNetMHT to convert a URL to a MHT document with the additional feature of
enabling logging for any troubleshooting purposes.
[ C# ]
string url = "http://www.google.com";
//create a unique filename because .mht
//files are cached by IE so any changes made
//to the same file will not be reflected
//unless the IE cache is cleared
string filename
= "c:\\temp\\" + DateTime.Now.ToFileTime().ToString() + ".mht";
MHT m = new MHT();
//enable logging for any troubleshooting
string logfile = "c:\\temp\\mht.log";
m.Logger = new MHTLog( logfile );
m.Logger.Enabled = true;
m.Logger.Overwrite = true;
//load the content from a remote url
m.LoadUrl( url );
//parse the HTML into it's MHT counterpart
m.Parse();
//save it to the filesystem
m.SaveToFile( filename );
[ VB.NET ]Dim url As String = "http://www.google.com"
'create a unique filename because .mht
'files are cached by IE so any changes made
'to the same file will not be reflected
'unless the IE cache is cleared
Dim filename As String
= "c:\temp\" + DateTime.Now.ToFileTime().ToString() + ".mht"
Dim m As New MHT()
'enable logging for any troubleshooting
Dim logfile As String = "c:\temp\mht.log"
m.Logger = New MHTLog(logfile)
m.Logger.Enabled = True
m.Logger.Overwrite = True
'load the content from a remote url
m.LoadUrl(url)
'parse the HTML into it's MHT counterpart
m.Parse()
'save it to the filesystem
m.SaveToFile(filename)
Converting a HTML string to a MHT Document
This sample builds a MHT document from a HTML formatted string.
[ C# ]
//create a unique filename because .mht files are cached by IE
//create a unique filename because .mht
//files are cached by IE so any changes made
//to the same file will not be reflected
//unless the IE cache is cleared
string filename
= "c:\\temp\\" + DateTime.Now.ToFileTime().ToString() + ".mht";
MHT m = new MHT();
//enable logging for any troubleshooting
string logfile = "c:\\temp\\mht.log";
m.Logger = new MHTLog( logfile );
m.Logger.Enabled = true;
m.Logger.Overwrite = true;
//load the content from a remote url
string html = "<html><body>Here is a picture of the company
logo <img src='http://www.mycompany.com/logo.gif'></body></html>";
m.LoadString( html );
//parse the HTML into it's MHT counterpart
m.Parse();
//save it to the filesystem
m.SaveToFile( filename );
[ VB.NET ]'create a unique filename because .mht files are cached by IE
'create a unique filename because .mht
'files are cached by IE so any changes made
'to the same file will not be reflected
'unless the IE cache is cleared
Dim filename As String
= "c:\temp\" + DateTime.Now.ToFileTime().ToString() + ".mht"
Dim m As New MHT()
'enable logging for any troubleshooting
Dim logfile As String = "c:\temp\mht.log"
m.Logger = New MHTLog(logfile)
m.Logger.Enabled = True
m.Logger.Overwrite = True
'load the content from a remote url
Dim html As String
= "<html><body>Here is a picture of the company
logo <img src='http://www.mycompany.com/logo.gif'></body></html>"
m.LoadString(html)
'parse the HTML into it's MHT counterpart
m.Parse()
'save it to the filesystem
m.SaveToFile(filename)
Converting a HTML file to a MHT Document
This sample builds a MHT document from a local HTML file.
[ C# ]
//create a unique filename because .mht files are cached by IE
//create a unique filename because .mht
//files are cached by IE so any changes made
//to the same file will not be reflected
//unless the IE cache is cleared
string filename
= "c:\\temp\\" + DateTime.Now.ToFileTime().ToString() + ".mht";
MHT m = new MHT();
//enable logging for any troubleshooting
string logfile = "c:\\temp\\mht.log";
m.Logger = new MHTLog( logfile );
m.Logger.Enabled = true;
m.Logger.Overwrite = true;
//explicitly allow aspNetMHT to read from the filesystem
m.AllowFileScheme = true;
//load the content from a local file
m.LoadFile( "c:\\temp\\sample.htm");
//parse the HTML into it's MHT counterpart
m.Parse();
//save it to the filesystem
m.SaveToFile( filename );
[ VB.NET ] 'create a unique filename because .mht files are cached by IE
'create a unique filename because .mht
'files are cached by IE so any changes made
'to the same file will not be reflected
'unless the IE cache is cleared
Dim filename As String
= "c:\temp\" + DateTime.Now.ToFileTime().ToString() + ".mht"
Dim m As New MHT()
'enable logging for any troubleshooting
Dim logfile As String = "c:\temp\mht.log"
m.Logger = New MHTLog(logfile)
m.Logger.Enabled = True
m.Logger.Overwrite = True
'explicitly allow aspNetMHT to read from the filesystem
m.AllowFileScheme = True
'load the content from a local file
m.LoadFile("c:\temp\sample.htm")
'parse the HTML into it's MHT counterpart
m.Parse()
'save it to the filesystem
m.SaveToFile(filename)