Generating Non-HTML Content


Using <cfcontent>, you can send documents to the client browser. The attributes you use with this tag are shown in Table 5.3.

Table 5.3. <cfcontent> Tag Attributes

ATTRIBUTE

DESCRIPTION

type

The MIME type of the document being sent.

file

The file to be sent to the browser. This attribute is mutually exclusive of the reset attribute.


deletefile

An optional attribute, which defaults to NO, that controls whether the file should be deleted after the download operation.

reset

An optional attribute, which defaults to YES, that determines whether any output before the <cfcontent> tag should be discarded. This attribute is mutually exclusive of the file attribute.


CAUTION

The reset attribute should be set to NO if the <cfcontent> tag is used in a custom tag. If this attribute is not set, all output from the page before the custom tag call will be discarded.


This example sends a Microsoft Word document to a browser:

 <cfcontent type="application/msword"             file="C:\MyWork.doc"             deletefile="No"> 

In addition to sending a file that is already created, you can send a document that is built on the fly. For instance, you might want to build an Excel spreadsheet to send to users, but with the absolutely latest data. You could use the following example. Assume that the ColdFusion variables Test.Name and Test.Price are read from the query:

 <cfcontent type="application/vnd.ms-excel"            reset="Yes">"Name","Price" <cfoutput query="Test">"#Test.Name#","#Test.Price#" </cfoutput> 

TIP

The reset attribute is very helpful in this example because it cleans up any text that might exist on the page before you start the spreadsheet. It is also helpful for cases in which XML packets are being produced and sent.

Also, the lack of a new line after the <cfoutput query="Test"> is intentional. All characters after <cfcontent> are used in the file, so a carriage return in this location would put a blank line between each row of data in the spreadsheet. Tabs separate the two labels that are the column heading names. Tabs also separate the two actual data column names.


NOTE

You can disable the <cfcontent> tag's functionality in ColdFusion Administrator.




Macromedia ColdFusion MX 7 Certified Developer Study Guide
Macromedia ColdFusion MX 7 Certified Developer Study Guide
ISBN: 0321330110
EAN: 2147483647
Year: 2004
Pages: 389
Authors: Ben Forta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net