This content has been marked as final. Show 2 replies
Did you find a way to do this?
Don't take my word on this, but I think this should work; I've done this in the past to send dynamically-generated CSV files to the user, which is in a way (at least at the perspective of what's being outputted to the user) the same thing.
First, obviously, you need to retrieve the Word document data from the database. We'll say you put that in a variable called 'wordDoc'.
<cfset wordDoc = someQuery.wordDataObj />
Next, we need to set the 'Content-disposition' HTTP header, to tell the client's browser that we're sending a file, and that we want you to call it somefile.doc by default. We'll do this with the <cfheader> tag (note that if you use <cfflush> in the application, this tag (and thus, this approach) will not work.
<cfheader name="Content-disposition" value="attachment; filename=somefile.doc" />
Almost there. Now we need to set the Content-type HTTP header, to tell the browser what kind of data is coming, and then give it the actual file data. We'll use the <cfcontent> tag to do both of these things.
<cfcontent type="application/msword" reset="yes">#wordDoc#</cfcontent><cfabort>
If memory serves, this should be all you need. Note the <cfabort> after the closing <cfcontent> tag, I've had problems in the past with additional output on the page after these tags being appended to what gets sent to the browser, so I use a <cfabort> afterwards to make sure nothing more gets sent after the data we want. Also, at least with CFMX7, I've noticed that debugging output tends to get added in too regardless, so I typically put a <cfsetting showdebugoutput="false" /> at the top of the file, too.
I can't guarantee this will work, I haven't tested this particular situation, but if it doesn't, it ought to be close. Let me know if I'm wrong.
Attached is what should be the code without my commentary / rambling interspersed.