Solved

writing a recordset to a text file

Posted on 2007-04-07
5
207 Views
Last Modified: 2013-12-24
I want to write data to a text file. I want to be able to control how the data will look in the text file so I was thinking of using recorddset fields and putting it all in one CF variable string and use cffile to output that one variable. I guess I want to know how to put all my data from my query into a single string variable.
0
Comment
Question by:techman36
5 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 18871673
You may wish to look at the last example here (see "to write all at once")
http://www.experts-exchange.com/Software/Server_Software/Web_Servers/ColdFusion/Q_20752794.html?qid=20752794
0
 
LVL 39

Accepted Solution

by:
gdemaria earned 50 total points
ID: 18873990

 Do you want a structured file (padded with spaces, every column has a fixed width) or a delimited file (field separated by a comma or other character)?

 This will output every column in your query and all records,  using the delimiter you specify...

<cfset variables.delimiter = "|">  <!--- the delimiter ---->
<cfloop query="myQuery">
  <cfset aRec = "">
  <cfloop index="aCol" list="#myQuery.columnList#">
     <cfset aRec = listAppend(aRec,myQuery[aCol][myQuery.currentRow],variables.delimiter)>  
  </cfloop>
 <cffile action="append" file="TheFile.txt" output="#aRec#">
</cfloop>
0
 

Expert Comment

by:singi007
ID: 18877492
You can use the following:

 <cfsavecontent variable="contentvar">
 <cfoutput>text
 text and more text. and formatting
 </cfoutput>
 </cfsavecontent>
 
<cffile action = "write"
  file = "c:\output\"
  output = "#contentvar#"
  mode = "777"
  attributes="normal">
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
need some regex help 15 25
Can I format excel columns with coldfusion 11? Using CFSPREADSHEET? 7 148
paging 3 28
change time in cron 4 40
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now