Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

writing a recordset to a text file

Posted on 2007-04-07
5
Medium Priority
?
225 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 150 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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…
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
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…
Suggested Courses

610 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