We help IT Professionals succeed at work.
Get Started

coldfusion create csv file  error

388 Views
Last Modified: 2015-12-03
I have the following cf code to export a query to excel csv file, when the file size is small, it was able to create a csv file without error.  But when the recs about 1000+, got error: "ColdFusion was unable to add the header you specified to the output stream. This is probably because you have already used a cfflush tag in your template or buffered output is turned off"

In the same server, other appl, I was able to create csv file with 2 MB.  Any suggestion what to check?

<cfif isdefined("testList.recordcount") AND testList.recordcount gt 0>

     <CFSET TXTOUTPUT = "">
      <CFSET OUTFILE = "C:\temp\testListFile_#dateformat(now(),'yyyymmdd')#.csv">

      
      <CFSET TXTCOLUMNS = '"Date","CompanyName","LastName","FirstName","Num"'>
      <CFIF #FILEEXISTS(OUTFILE)# IS "No">
              <CFFILE ACTION="WRITE" FILE="#OUTFILE#" OUTPUT="#TXTCOLUMNS#">
      </CFIF>

      <CFLOOP QUERY="testList">
              <CFSET TXTOUTPUT = '"#dateFormat(SERVICE_DATE, "MM-DD-YYYY")#","#COMPANY_NAME#","#LAST_NAME#","#FIRST_NAME#","#Number#"'>
              <CFFILE ACTION="APPEND" FILE="#OUTFILE#" OUTPUT="#TXTOUTPUT#">      
      </CFLOOP>
      <CFSET filename = "tesListFile_#dateformat(now(),'yyyymmdd')#.csv">
      <CFHEADER  NAME="content-disposition" VALUE="attachment; filename=#filename#">
      <CFCONTENT  TYPE="APPLICATION/MSEXCEL" FILE="#OUTFILE#" DELETEFILE="TRUE" RESET="TRUE">

</cfif>
Comment
Watch Question
Principal Systems Engineer
CERTIFIED EXPERT
Top Expert 2005
Commented:
This problem has been solved!
Unlock 1 Answer and 31 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE