SQL Server
SQL Server
Exclude Resources Matching a Pattern
See more MHT / HTML Email Examples
Demonstrates Mht.ExcludeImagesMatching, which adds an exclusion pattern used while gathering embeddable resources, so matching resources are omitted from the archive.
Background. Despite the method name, the test applies to embeddable resources generally, not only images. Each candidate is tested against its fully resolved reference — an absolute URL for web content, or the resolved local path for a local resource.
Chilkat SQL Server Downloads
-- 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 exclusion pattern for embeddable resources. Each candidate resource is tested against its
-- fully resolved reference (an absolute URL for web content), so resources whose reference matches
-- the pattern are omitted from the archive. Here, resources ending in ".gif" are excluded.
EXEC sp_OAMethod @mht, 'ExcludeImagesMatching', NULL, '*.gif'
-- Create the MHT web archive without the excluded resources.
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