SQL Server Stored Procedure Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

SQL Server
Stored Procedure Examples

Quick Start
Encryption
File Access
IMAP
POP3
SMTP
Email Object
FTP
HTML-to-XML
HTTP
MHT
MIME
RSA Encryption
Diffie-Hellman
DSA
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
String
Tar
Upload
XML
XMP
Zip

Byte Array
RSS
Atom
Self-Extractor

Modify Content-Disposition Header Fields in MIME

Demonstrates how to edit the Content-Disposition header in MIME sub-parts.

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)

    --  The intent of this example is to modify Content-Disposition
    --  header fields from this:
    -- 
    --  Content-Disposition: attachment; filename="a4 manuscript.pdf"; size=0;
    --  	creation-date="Thu, 12 Apr 2007 06:39:10 GMT";
    --  	modification-date="Thu, 12 Apr 2007 06:39:10 GMT"
    -- 
    --  to this:
    -- 
    --  content-disposition: attachment;
    --  	 filename="a4 manuscript.pdf"
    -- 

    DECLARE @mime int
    EXEC @hr = sp_OACreate 'Chilkat.Mime', @mime OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    EXEC sp_OAMethod @mime, 'UnlockComponent', @success OUT, 'Anything for 30-day trial'
    IF @success = 0
      BEGIN
        PRINT 'Failed to unlock'
        RETURN
      END

    EXEC sp_OAMethod @mime, 'LoadMimeFile', @success OUT, 'testMime.txt'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END

    --  This example assumes the header fields to be modified
    --  are located directly beneath the top-level MIME part.
    DECLARE @numParts int

    EXEC sp_OAGetProperty @mime, 'NumParts', @numParts OUT

    DECLARE @i int

    DECLARE @mimePart int

    DECLARE @filename nvarchar(4000)

    DECLARE @disposition nvarchar(4000)

    SELECT @i = 0
    WHILE @i <= @numParts - 1
      BEGIN
        EXEC sp_OAMethod @mime, 'GetPart', @mimePart OUT, @i

        EXEC sp_OAGetProperty @mimePart, 'Disposition', @disposition OUT

        IF @disposition = 'attachment'
          BEGIN
            EXEC sp_OAGetProperty @mimePart, 'Filename', @filename OUT

            --  AddHeaderField replaces the existing field if it already exists.
            --  Discard the contents of the existing Content-Disposition
            --  and replace it with "attachment".
            EXEC sp_OAMethod @mimePart, 'AddHeaderField', NULL, 'content-disposition', 'attachment'

            --  Now add the filename attribute:
            EXEC sp_OASetProperty @mimePart, 'Filename', @filename
          END

        SELECT @i = @i + 1
      END

    EXEC sp_OAMethod @mime, 'SaveMime', @success OUT, 'modifiedMime.txt'


END
GO

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.