SQL Server Stored Procedure Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

SQL Server
Stored Procedure Examples

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

Amazon S3
Bz2
CSV
FileAccess
Byte Array
RSS
Atom
Self-Extractor

Load file into XML as Base64 Encoded Content

Loads any type file into an XML document. The file content is encoded as base64.

Download Chilkat XML ActiveX

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @docRoot int
    EXEC @hr = sp_OACreate 'Chilkat.Xml', @docRoot OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    EXEC sp_OASetProperty @docRoot, 'Tag', 'myDoc'

    --  To zip compress the content, set this flag to 1
    DECLARE @zipContent int

    SELECT @zipContent = 0
    --  To 128-bit AES encrypt the content, set this flag to 1
    DECLARE @encryptContent int

    SELECT @encryptContent = 0
    DECLARE @encryptPassword nvarchar(4000)

    SELECT @encryptPassword = ''

    DECLARE @pdfNode int

    EXEC sp_OAMethod @docRoot, 'NewChild', @pdfNode OUT, 'pdf', ''

    --  Embed a PDF into XML
    EXEC sp_OAMethod @pdfNode, 'SetBinaryContentFromFile', @success OUT, 'sample.pdf', @zipContent, @encryptContent, @encryptPassword
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @pdfNode, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0

        RETURN
      END
    EXEC sp_OAGetProperty @pdfNode, 'LastErrorText', @sTmp0 OUT
    PRINT @sTmp0

    --  Display the entire XML document:
    EXEC sp_OAMethod @docRoot, 'GetXml', @sTmp0 OUT
    PRINT @sTmp0

    --  Get the Base64-encoded content and display it:
    EXEC sp_OAGetProperty @pdfNode, 'Content', @sTmp0 OUT

    PRINT @sTmp0

    --  Extract the binary content from XML:
    DECLARE @unzipContent int

    SELECT @unzipContent = 0
    DECLARE @decryptContent int

    SELECT @decryptContent = 0
    DECLARE @decryptPassword nvarchar(4000)

    SELECT @decryptPassword = ''
    EXEC sp_OAMethod @pdfNode, 'SaveBinaryContent', @success OUT, 'out.pdf', @unzipContent, @decryptContent, @decryptPassword
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @pdfNode, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0

        RETURN
      END

    PRINT 'Success!'
END
GO

 

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