Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

cfsavecontent and cffile

LEGEND ,
Sep 26, 2008 Sep 26, 2008
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.
TOPICS
Advanced techniques
2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Sep 26, 2008 Sep 26, 2008
LATEST
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)#">
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources