1 Reply Latest reply on Sep 26, 2008 1:35 PM by -==cfSearching==-

    cfsavecontent and cffile

    Dan Bracuk Level 5
      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.
        • 1. Re: cfsavecontent and cffile
          -==cfSearching==- Level 4
          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)#">