SQL Server
SQL Server
Unpack an MHT Archive into Files
See more MHT / HTML Email Examples
Demonstrates Mht.UnpackMHT, which extracts an MHT archive into its constituent parts: the HTML document and its referenced resources.
The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background. The source may be an MHT file path or the literal MHT MIME text. The HTML is written under the chosen filename, and the referenced parts (images, style sheets, etc.) are written into a sub-directory.
Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
DECLARE @mht int
EXEC @hr = sp_OACreate 'Chilkat.Mht', @mht OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- The file paths are relative to the application's current working directory. Absolute paths
-- may also be used. Supply the paths appropriate to your own environment.
-- Unpack an MHT file into its constituent parts. The 1st argument may be an MHT file path or the
-- literal MHT MIME text. The 2nd argument is the directory to unpack into, the 3rd is the filename
-- for the extracted HTML, and the 4th is the sub-directory (relative to the unpack directory) for the
-- referenced parts such as images and style sheets.
EXEC sp_OAMethod @mht, 'UnpackMHT', @success OUT, 'qa_data/page.mht', 'qa_output/unpacked', 'index.html', 'parts'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @mht, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @mht
RETURN
END
PRINT 'MHT unpacked.'
EXEC @hr = sp_OADestroy @mht
END
GO