Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


ColdFusion 5 - Make Word have the right filename

Posted on 2003-03-12
Medium Priority
Last Modified: 2013-12-24
I have a page that displays an invoice in MS-Word inside the IE Browser.  This all works fine, I use CFCONTENT to tell the browser to open the word app.  However, while you are in Word-in-a-browser, if the user goes to File->Save As..., the suggested filename and default directory are useless.

Is there a way, using CFHEADER or something, to suggest the correct filename to Word?  Note that I am using IE6.  Some people are using Word 2000 and some people are using Word XP.  Although a solution for Word XP is more important.


Question by:curmudgeon42
  • 3
  • 2
  • 2
  • +1

Expert Comment

ID: 8119918
It is a matter of the url requesting the page. See below. An example of one page linking to another that serves up the file. The url string after the cfm defines the file save name.
##Link to the CF file serving up the file ## INDEX.CFM ##
<a href="GetFile.cfm/coolfile.zip">Click Here</a>
## /INDEX.CFM ##

##Serve up the file ## GetFile.cfm ##
<cfcontent type="application/zip"
## /GetFile.cfm ##

Author Comment

ID: 8119954
We aren't loading a file from the server hard drive.  We are building the file dynamically and telling IE that the incoming file should be loaded in Word.

Expert Comment

ID: 8120152
I say again. It is a matter of the url requesting the file. Here is another example. To get the file to save as "myworddoc.doc" link to the file like this:

"<a href="servitup.cfm/myworddoc.doc">LINK</a>"

ServeItUp.cfm creates the word doc and when you save it word looks at the url and the last file name it sees is the "myworddoc.doc", and it saves it as "myworddoc.doc".
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.


Author Comment

ID: 8139380
that doesn't work - eventually i had to write the HTML (destined for Word) to a file and then do a CFLOCATION to the file so that it would have the right filename - i then later had to put some code which would look for these old temp files and take care of them

Expert Comment

ID: 8143777
Try this:

Run your query or do whatever to build output.

Then add these lines:
<cfheader name="Content-Disposition" value="attachment; filename=""WORDOUTPUT.doc""">
<cfcontent type="application/msword">

Then write you output normally using <CFOUTPUT> or whatever.

The browser should ask you to OPEN/SAVE document. This works in multi user environments also.

Expert Comment

ID: 8479994
DynAstY that header is new to me. curmudgeon42, does that work. I think it is the answer. I know I can use it. Thanks DynAstY.

Accepted Solution

DynAstY earned 200 total points
ID: 8480557
It works for me :)
LVL 35

Expert Comment

ID: 10940568
No comment has been added lately, so it's time to clean up this question.
I will leave the following recommendation in the Cleanup topic area:

Accept DYnAstY

Please leave any comments here within the next four days.

EE Cleanup Volunteer

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question