Solved

writing a recordset to a text file

Posted on 2007-04-07
5
214 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

770 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