For some reason, I got interested in this. Here's a little proof of concept. I swear it works on my system... <vbg> If the list wraps it too much, let me know and I'll email the PRG to you.
#DEFINE CRLF CHR(13)+CHR(10) ************************************** * Program: SAVEDOCTOSQL1.PRG * Date: 06/02/2010 06:45:21 PM * VFP Version: Visual FoxPro 09.00.0000.7423 for Windows * Notes: ************************************** #DEFINE MB_OK 0 #DEFINE MB_ICONSTOP 16 #DEFINE MB_ICONINFORMATION 64 TRY ACTIVATE SCREEN CLEAR TEXT CREATE a table in SQL server with the following structure: pkey int identity not null filename varchar(50) null doc varbinary(max) null CREATE a connection to the DB that contains the table. ENDTEXT WAIT WINDOW CLEAR LOCAL m.cDoc AS String, m.lcCaption AS Character, m.lnHandle AS Integer m.lcCaption=[There & Back Again...] m.lcProblem=[Something's not quote right...] m.lnHandle=0 m.lcDocument=GETFILE('doc',[Get document],[Select]) m.cDoc=FILETOSTR(m.lcDocument) m.cDocBlob=CAST(m.cDOC AS BLOB) TEXT TO cCmd TEXTMERGE NOSHOW FLAGS 1 PRETEXT 1+2+4+8 INSERT INTO test (filename) VALUES ('<<JUSTFNAME(m.lcDocument)>>') ENDTEXT m.lnHandle=SQLCONNECT() && assumes connection you want is available IF m.lnHandle>0 IF SQLExec(m.lnHandle, m.cCmd)>0 && record was inserted MESSAGEBOX([Record inserted],MB_OK+MB_ICONINFORMATION, m.lcCaption) TEXT TO cCmd TEXTMERGE NOSHOW FLAGS 1 PRETEXT 1+2 UPDATE test SET doc=?cDocBlob WHERE filename='<<JUSTFNAME(m.lcDocument)>>' ENDTEXT IF SQLEXEC(m.lnHandle, m.cCmd)>0 && query did not fail (although that doesn't mean it actually changed data) MESSAGEBOX([Record updated],MB_OK+MB_ICONINFORMATION, m.lcCaption) ELSE AERROR(aSQLError) MESSAGEBOX(asqlerror[2]+CRLF+asqlerror[3],MB_OK+MB_ICONSTOP, m.lcProblem) ENDIF TEXT TO cCmd TEXTMERGE NOSHOW FLAGS 1 PRETEXT 1+2+4+8 SELECT TOP 1 filename, doc FROM test WHERE filename='<<JUSTFNAME(m.lcDocument)>>' ORDER BY pkey DESC ENDTEXT IF SQLEXEC(m.lnHandle, m.cCmd, [retrieved])>0 && record was retreived MESSAGEBOX([Record retrieved],MB_OK+MB_ICONINFORMATION, m.lcCaption) SELECT CAST(retrieved.doc AS blob) doc, filename FROM retrieved INTO CURSOR temp SCATTER MEMVAR MEMO FIELDS doc, filename m.filename=JUSTSTEM(m.filename)+[test.]+JUSTEXT(m.filename) ?STRTOFILE(m.doc, m.filename) && echoes number of bytes to screen IF FILE(FULLPATH(m.filename)) LOCAL m.loWord AS word.application m.loWord=NEWOBJECT([word.application]) m.loWord.Documents.Add(FULLPATH(m.filename)) ENDIF ELSE AERROR(aSQLError) MESSAGEBOX(asqlerror[2]+CRLF+asqlerror[3],MB_OK+MB_ICONSTOP, m.lcProblem) ENDIF ELSE AERROR(aSQLError) MESSAGEBOX(asqlerror[2]+CRLF+asqlerror[3],MB_OK+MB_ICONSTOP, m.lcProblem) ENDIF ENDIF CATCH TO m.loError LOCAL m.lcError AS Character m.lcError=[ Error: ] + STR(m.loError.ErrorNo) + CRLF m.lcError=m.lcError+[ LineNo: ] + STR(m.loError.LineNo) + CRLF m.lcError=m.lcError+[ Message: ] + m.loError.Message + CRLF m.lcError=m.lcError+[ Procedure: ] + m.loError.Procedure + CRLF m.lcError=m.lcError+[ Details: ] + m.loError.Details + CRLF m.lcError=m.lcError+[ StackLevel: ] + STR(m.loError.StackLevel) + CRLF m.lcError=m.lcError+[ LineContents: ] + m.loError.LineContents MESSAGEBOX(m.lcError,MB_OK+MB_ICONSTOP,[*ERROR*]) FINALLY USE IN SELECT([temp]) USE IN SELECT([retrieved]) IF m.lnHandle>0 SQLDISCONNECT(m.lnHandle) ENDIF IF VARTYPE(m.loWord)=[O] m.loWord.Visible=.t. ENDIF ENDTRY rk -----Original Message----- From: profoxtech-boun...@leafe.com [mailto:profoxtech-boun...@leafe.com] On Behalf Of Rafael Copquin Sent: Wednesday, June 02, 2010 6:05 PM To: profoxt...@leafe.com Subject: VFP and SQL Server + Word files OK Dave and Steve I followed Dave's instructions, ie, use the cast function after the filetostr function and IT WORKED !!! _______________________________________________ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://leafe.com/mailman/listinfo/profox OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/df1eef11e586a64fb54a97f22a8bd04406842f0...@ackbwddqh1.artfact.local ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.