Solved

Opening a file using cfheader/cfcontent

Posted on 2001-07-08
5
1,100 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
ID: 6263231
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
ID: 6263304
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
ID: 6263826
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
ID: 33420215
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
ID: 33420300
Nevermind, I realized I was missing "filename" after "attachment;"
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

910 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

16 Experts available now in Live!

Get 1:1 Help Now