Downloads a file from the server to the client. Sets the file or MIME content encoding of content returned by the current page. Sets the name of a file that is downloaded by the current page.
Note: For this tag execute, it must be enabled in the ColdFusion Administrator. For more information, see Administering ColdFusion MX.
<cfcontent type = "file_type" deleteFile = "Yes" or "No" file = "filename" reset = "Yes" or "No">
Note: If you call this tag from a custom tag, and you do not want the tag to discard the current page when it is called from another application or custom tag, set reset = "no".
To set the character encoding of generated output, use code such as the following:
<cfcontent type="text/html; charset=ISO-8859-1">
If a file delete operation is unsuccessful, ColdFusion throws an error.
When ColdFusion processes an HTTP request, it determines the character set of the data returned in the HTTP response. By default, ColdFusion returns character data using the Unicode UTF-8 format (regardless of the value of an HTML meta tag in the page). Within a ColdFusion page, you can override the default character encoding of the response, using the cfcontent tag. To specify the MIME type and character set of the page output, use the type attribute, as follows:
<cfcontent type="text/html charset=EUC-JP">
The following example shows how you might display the results of a query, in an Excel spreadsheet within a ColdFusion page.
<!--- use cfsetting to block output of HTML that is not within cfoutput tags --->
<cfsetting enablecfoutputonly="Yes"> <!--- get Employee info ---> <cfquery name="GetEmps" datasource="CompanyInfo"> SELECT * FROM Employee </cfquery> <!--- Set variables for special chars ---> <cfset TabChar = Chr(9)> <cfset NewLine = Chr(13) & Chr(10)> <!--- Set content type to invoke Excel ---> <cfcontent type="application/msexcel"> <!--- suggest default name for XLS file ---> <!--- use "Content-Disposition" in cfheader for Internet Explorer ---> <cfheader name="Content-Disposition" value="filename=Employees.xls"> <!--- output data, each row on one line---> <cfloop query="GetEmps"> <cfoutput>#Emp_ID##TabChar##LastName# #TabChar##FirstName##TabChar##Salary##NewLine#</cfoutput> </cfloop>
If you use this tag after the cfflush tag on a page, ColdFusion throws an error.
<!--- This example shows the use of cfcontent to return the contents of the CF Documentation page dynamically to the browser. You might need to change the path and/or drive letter. (graphics do not display) ---> <!--- Files may be set to delete after downloading, allowing for posting of changing content. ---> <cfcontent type = "text/html" file = "c:\inetpub\wwwroot\cfdocs\main.htm" deleteFile = "No"> <!--- This example shows how reset attribute changes text output. ---> <html> <body> <h3>cfcontent Example 2</h3> <p>This example shows how reset attribute changes output for text.</p> <p>reset = "Yes ": 123 <cfcontent type = "text/html" reset = "Yes ">456</p> <p>This example shows how reset attribute changes output for text.</p> <p>reset = "No ": 123 <cfcontent type = "text/html" reset = "No ">456</p>
ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting
Version 6
Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/Tags-pt118.htm
Comments
hlichtin said on Mar 10, 2003 at 2:36 PM : h2oman said on Jun 21, 2002 at 3:17 PM : ctina said on Jul 19, 2002 at 6:59 PM : sundvor said on Aug 15, 2002 at 5:46 AM : mikv said on Sep 10, 2002 at 2:11 PM : sandeep_chheda said on Dec 16, 2002 at 3:52 AM : faceless said on Feb 26, 2003 at 4:54 PM : Len said on Aug 9, 2003 at 5:01 PM : mliving said on Aug 22, 2003 at 2:11 PM : No screen name said on Dec 18, 2003 at 11:55 AM : lmr1010 said on Feb 4, 2004 at 8:31 AM : cfdawna said on Apr 5, 2004 at 6:12 AM : big_web_monkey said on May 22, 2004 at 4:38 PM :