Skip to main content
Inspiring
September 26, 2008
Question

cfsavecontent and cffile

  • September 26, 2008
  • 1 reply
  • 2300 views
No doubt I am doing something wrong here. In the past, if I wanted to write query results to a file, I would do this:

<cffile action = "write" output = "">
<cfoutput query ="q">
<cffile action = "action=" output = "#querydata#">
etc
Worked great so I thought I'd try something suggested in these forums, this:
<cfsavecontent variable = "x">
<cfoutput query ="q">
#data#
closing tags
<cffile action = "write" output = "#x#">

When I opened the file to see how it turned out, I got unexpected results. After some experimentation I concluded that and white space in the source code between the opening and closing cfcontent tags were being written to the file.

Back to the old method.
This topic has been closed for replies.

1 reply

Inspiring
September 26, 2008
Dan Bracuk wrote:
> When I opened the file to see how it turned out, I got unexpected results

Probably whitespace where you did not expect it? I observed those results too. But then I remembered cfsavecontent captures whitespace. So the placement of tags and newlines matters. Something like this works correctly. Though I usually use the old concatenated string method myself.

<cfsavecontent variable="output"><cfoutput query="q">#Col1#,#Col2#
</cfoutput>
</cfsavecontent>
<cffile action="write" file="#ExpandPath('./test.txt')#" output="#trim(output)#">