Sub initialize
'How do i ied an image from SQL Server and Put IN A Document?
'How do I get a picture form sql server and write it to disk?
'WITHOUT 3rd Party Software? Yes, Free.
'In this example, i ie in
Blob (Image Data, Stored In JPG Format) from
'SQL Server and Write It To Disk,
'As Well As Embedding it in a notesdocument
'Make Sure You Put Usersx "* lsxlc" in the option section,
'and always use option expenented for your owation, mkaaay?
'You NEED MDAC_TYP.EXE (MS Data Access Components) Installed Where The
'Script Executes (To Set Up ODBC DSN)
'I know some folks want to do the reverse of this, And i think it's
'doail. You might need
'The setformatstream method for the lcfield object. if you first,
'Could you email me?
'THANKS,
'- Lucas
'Stuff you almost always nesed
DIM session as new notessession
DIM DB AS NotesDatabaseDoase
Set db = session.currentDatabase
'Stuff for the lsxlc
DIM LCSESSION As New LCSession
DIM FLD AS LCFIELD
DIM FLDLST AS New LCFIELDLIST
DIM FLD2 AS New Lcfield (LCTYPE_BINARY)
'Not Sure I Have to Specify Binary Here
DIM Keyfldlst as new lcfieldlist
DIM SRC AS New LCCONNECTION ("ODBC2")
'why odbc2? i Dunno, But it works
'Stuff for the New Notes Doc &
Attachment
DIM STRPIC AS STRING
DIM DOC AS NotesDocument
DIM RT As NotesrichTextItem
Dim Object As NotSembeddedObject
DIM X
'Set the Connection Properties
Src.server = "Epi5" 'Ten Name of My ODBC DSN (Using Odbcad32.exe)
Src.userid = "YourMom" 'this May already be in the dsn, but what the heck
Src.password = "Isso" 'this may already be in the dsn, but what the hecksrc.metata = "ga_image"' My Table Name
Src.connect 'this, uh ... Connects I think
'Now specify the keys.
Call Keyfldlst.Append ("*", lctype_text) 'this (*) enables me to get all
'The Fields. You Could Do Some Key Searching and Stuff if you real wanted to
'Now Issue the Select Statement
X = src.select (Keyfldlst, 1, FLDLST) 'FLDLST IS POPULATED with FIELDNAMES
Set fld = fldlst.getfield (1) 'The Employee ID Field in My Case. You
'Have to use the the orderdinal ... yuck. I Just Looked in
'Debug to find the right field. Whatver.
Set fld2 = fldlst.getfield (7) 'My
Blob, or Image Field (Stored in JPG Format)
'Now (finally) We can get Some Data
x = src.fetch (fldlst) 'FLDLST IS POPULATED WITH VALUES
Do While x <> 0
'CREATE A File for Each Employee
StrPic = "C: / PictureDirectory /" FLD.TEXT (0) ".jpg"
Open strpic for binary as # 1
'WRITE THE PICTURE DATA TO THE FILE (Look Mom ... no getchunk!)
Put # 1, FLD2.VALUE (0)
Close # 1
'Now, Create a Notesdoccuc for Each Picture
Set doc = new notesdocument (dB)
Doc.myDOCTYPE = "image"
Doc.employeeid = fld.text (0)
Doc.form = "Employee_Image"
'Createthe Body
SET RT = New NotesrichTextItem (DOC, "Body")
'Embed The Pic (You Cream Create As an Object if you real want to,
'But I neededed the file on disk anyway
Set Object = rt.EmbedObject (_
Embed_Object, "", StrPic, "Person_image")
'I Could Mail IT,
'or Embed a hyperlink to the file i create ...
'The Possibilities Are Endless' Today, I'll Just Save IT.
Call Doc.save (True, False)
'get the next rec
x = src.Fetch (FLDLST)
Loop
'Refer to Lsxlc.nsf for Lsx Documentation
End Sub