Solved

Opening a file using cfheader/cfcontent

Posted on 2001-07-08
5
1,095 Views
Last Modified: 2013-12-24
Hi

I am having trouble with opening a file using cfcontent.  The filename presented in the open/save dialog is the name of the cfm page.  I have tried using a cfheader, but that does not help either:

<CFHEADER NAME="Content-disposition" value="attachment; filename=#MyFile#">
<CFCONTENT TYPE="unknown" DELETEFILE="No" FILENAME="#MyFile#">

I have also tried using the inline value for cfheader to no avail.

The file I want to open has the extension .jrp, and I want the file to open the associated application using the filename as a parameter.  I have registered the filetype .jrp in windows explorer.

What am I doing wrong?

Regards
John
0
Comment
Question by:jdthedj
  • 2
  • 2
5 Comments
 
LVL 4

Accepted Solution

by:
CF_Spike earned 100 total points
Comment Utility
Here is an example which should work and ought to point you in the right direction:

Create a file called test.jrp

In the same directory create two cfm files - index.cfm and download.cfm. The code for these two files is below:

index.cfm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
     <title>cfcontent</title>
</head>

<body>
<A HREF="download.cfm">force download</A>
             
           

</body>
</html>


download.cfm

<CFSET filename = "test.jrp">
<CFSET fullpath = "C:\InetPub\wwwroot\test.jrp">

<cfheader name="Content-Disposition" value="attachment; #variables.filename#">
<CFCONTENT TYPE="text/plain"
           FILE="#variables.fullpath#"
           DELETEFILE="No">

Browse to index.cfm and click the link. You should be prompted to save test.jrp. You can change this filename in any way you want to make it dynamic, but you will need to make sure that you use the full path with cfcontent.

Spike
0
 
LVL 3

Author Comment

by:jdthedj
Comment Utility
Hi Spike

Thanks for the reply.  I have done what you have suggested, but the dialog is still coming up with "You have chosen to download a file from this location download.cfm from Server"

Any ideas?

John
0
 
LVL 3

Author Comment

by:jdthedj
Comment Utility
Hello again Spike - I persevered with the code you gave me, and it works with inline instead of attachment.

Thanks for your help

John
0
 

Expert Comment

by:frostino
Comment Utility
Neither inline or attachment worked me for.  I still get the dialog box with the default filename of download.cfm .

I use the following code on the download.cfm page and I'm passing a URL param from another page because I have multiple files to download.  All files are in the same directory as the download.cfm so the path is basically the filename.


<cfheader name="Content-Disposition" value="attachment; #url.download#">

<CFCONTENT TYPE="audio/mpeg"

           FILE="#url.download#"

           DELETEFILE="No">

Open in new window

0
 

Expert Comment

by:frostino
Comment Utility
Nevermind, I realized I was missing "filename" after "attachment;"
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now