Solved

writing a recordset to a text file

Posted on 2007-04-07
5
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
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 integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. 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 : Go t…

729 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