Solved

writing a recordset to a text file

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IIS 404 Error on website Automatic Redirect to /help 5 50
paging 3 37
ColdFusion Need assistance updating my legacy zip function 13 36
Problem to go to Web page 2 97
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
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 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…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…

920 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