Sample code for 30+ languages & platforms
SQL Server

Add an External Style Sheet for MHT Conversion

See more MHT / HTML Email Examples

Demonstrates Mht.AddExternalStyleSheet, which adds a style-sheet URL to the list of external CSS resources downloaded and embedded during conversion.

Background. This is normally unnecessary because Chilkat automatically discovers references present in the static HTML. It is useful when a stylesheet is applied by means Chilkat cannot detect from the static markup.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @mht int
    EXEC @hr = sp_OACreate 'Chilkat.Mht', @mht OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    --  Add an external style-sheet URL to the list of CSS resources downloaded and embedded during
    --  conversion.  This is normally unnecessary because Chilkat automatically discovers
    --  <link rel="stylesheet"> references in the static HTML.
    EXEC sp_OAMethod @mht, 'AddExternalStyleSheet', NULL, 'https://example-code.com/crumb/style.css'

    --  Create the MHT web archive.  The external style sheet is downloaded and embedded.
    DECLARE @mhtText nvarchar(4000)
    EXEC sp_OAMethod @mht, 'GetMHT', @mhtText OUT, 'https://example-code.com/crumb/index.html'
    EXEC sp_OAGetProperty @mht, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @mht, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mht
        RETURN
      END

    PRINT @mhtText

    EXEC @hr = sp_OADestroy @mht


END
GO