Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating and viewing files

Status
Not open for further replies.

kss1133

Programmer
Mar 22, 2006
22
US
I am new to coldfusion, and I have created a page that will create a .csv file from a recordset (not sure if I am creating the file correctly or not), but now I need the user to be able to download this file.
Thanks for any help. Code included.

<cfquery datasource="#settings.dsn#" name="qData">
SELECT
compID,
companyName,
addressLine1,
addressLine2,
city
...shortend for readability.
FROM
company
ORDER BY
companyname,compid

</cfquery>
<!--- <cfoutput>#outputfile#</cfoutput>--->
<cfset DateTime = DateFormat(Now(), "mm/dd/yyyyhh:mm:ss")>

<!--- <cfoutput>#DateFormat(Now(), "mm/dd/yyyy hh:mm:ss")#</cfoutput>
<cfoutput>// #DateTime#</cfoutput><br>--->

<cfset DateTime = Replace(DateTime,"/","","all")>
<!--- //<cfoutput> //#DateTime#</cfoutput><br>--->

<cfset DateTime = Replace(DateTime,":","", "all")>
<!---<cfoutput> #DateTime#</cfoutput><br> --->


<cfscript>
outputFile = getDirectoryFromPath(GetCurrentTemplatePath()) & #DateTime# & ".csv";
oFileWriter = CreateObject("java","java.io.FileWriter").init(outputFile,JavaCast("boolean","true"));
oBufferedWriter = CreateObject("java","java.io.BufferedWriter").init(oFileWriter);
</cfscript>

<cfset rtnHeaders = "companyName,addressLine1,addressLine2,city,state,zip,phone,fax,infoEmail,url,descconcat,CompanyType,numEmplSt,numEmplTot,hqloc,yrest,annualSales,percentIntlSales,ownTypePublic,ownTypePrivate,ownTypeWomen,ownTypeMinority,stockExch,ForeignDistribution,workforce,softAppAll,CompanyOffers,VentureFunding" & chr(13) & chr(10)>


<cfset oBufferedWriter.write(#rtnHeaders#)>

<cfloop query="qData">
<cfset oBufferedWriter.write(companyName & "," & addressLine1 & "," & addressLine2 & "," & city & "," & state & "," & zip & "," & phone & "," & fax & "," & infoEmail & "," & url & "," & descconcat & "," & CompanyType & "," & numEmplSt & "," & numEmplTot & "," & hqloc & "," & yrest & "," & annualSales & "," & percentIntlSales & "," & ownTypePublic & "," & ownTypePrivate & "," & ownTypeWomen & "," & ownTypeMinority & "," & stockExch & "," & ForeignDistribution & "," & workforce & "," & softAppAll & "," & CompanyOffers & "," & VentureFunding & chr(13) & chr(10))>
</cfloop>
<!--- <a href=#outputfile# >file</a>

<cfoutput> #outputFile# </cfoutput> --->
<cfset oBufferedWriter.close()>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top