Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Convert HTML String to MHT Demonstrates how to convert an in-memory HTML string to a .mht file. The HTML includes an image that is loaded from the local filesystem. Dim mht As New Chilkat.Mht()
mht.UnlockComponent("anything for 30-day trial")
' Convert HTML to MHT. All referenced images are embedded in the MIME string
' returned. Referenced images (or other items referenced from within the HTML)
' should be:
' (1) A URL
' (2) A file on the local system with an absolute pathname.
' (3) A file on the local system with a relative pathname that correctly resolves
' from the calling process' current working directory.
Dim mhtStr As String
mhtStr = mht.HtmlToMHT("<html><head><META http-equiv=""Content-Type"" content=""text/html; charset=iso-8859-7""></head><body>This is a test<br /><img src=""images/dude.gif"" /></body></html>")
' IMPORTANT: You do not want to write the .mht file in this way. By doing so, the
' StreamWriter class writes the utf-8 preamble to the file. When you try to open the .mht
' in Internet Explorer, it will load as a text file displaying the MIME source.
Dim appendMode As Boolean = False ' This overwrites the entire file.
Dim sw As New System.IO.StreamWriter("outBad.mht", appendMode, System.Text.Encoding.UTF8)
sw.Write(mhtStr)
sw.Close()
' Use this code to write the .mht instead.
Dim sw2 As New System.IO.StreamWriter("outGood.mht", appendMode, System.Text.Encoding.ASCII)
sw2.Write(mhtStr)
sw2.Close()
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.