Skip to main content
Participant
September 25, 2008
Question

Creating a flat file in Cold Fusion

  • September 25, 2008
  • 2 replies
  • 376 views


Hi, I am trying to create a text file from a cfquery.

I am using the cfsavecontent command and would like to have only the result of the query (40 records of 3 fields each), one record per line. To do so, I need to use <br> to change line, but the <br> appears in my file.

Is there a way to avoid this ?

Thank you in advance to anyone who can help ...
    This topic has been closed for replies.

    2 replies

    Inspiring
    September 25, 2008
    MarieLaro wrote:
    > To do so, I need to use <br> to change line, but the <br> appears in my file.

    Cfsavecontent should preserve line breaks. This produced a text file with four lines for me.

    <cfset q = queryNew("")>
    <cfset queryAddColumn(q, "Col1", listToArray("test,test,test,test"))>
    <cfset queryAddColumn(q, "Col2", listToArray("this,that,this,that"))>

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

    If needed use your o/s new line character, rather than the html line break. (ie chr(13)&char(10), etc...)
    Inspiring
    September 25, 2008
    use #chr(13)&chr(10)# instead of <br>

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/