Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1138
  • Last Modified:

Extra carriage return in <cffile> created tab delimited text file

I have created a script that converts a number of records in a database to a tab delimited text file and emails the file to the person who needs to import it into their own database. This was working a few weeks ago and some minor change (?) has caused it to regularlt return a file that adds an extra blank line between each record. I have poured over this code, viewed it in a text editor to see hidden characters, removed the hard return and substituted <cfset newline=Chr(13& Chr(10> and then used #newline# instead of the hard return. Here is the current code: (not including the query and with email addresses removed)

I am stumped.

<cfsetting enablecfoutputonly="yes"></head><body><cfsavecontent variable="admissions_file"><cfloop query="freshman"><cfoutput>"#Title#"      "#Name#"      "#Middle#"      "#Last#"      "#Address#"      "#Address2#"      "#City#"      "#State#"      "#Zip#"      "#Country#"      "#Email#"      "#Interest#"      "#Year#"      "#Date#"      "#ID#"      "#Trim(Degree)#"
</cfoutput></cfloop></cfsavecontent><cfoutput><cffile action="write" output="#admissions_file#" file="filepath\freshman.#DateFormat(Now(),'mmddyy')#.txt" nameconflict="overwrite"> </cfoutput><cfmail from="email@email.com" to="email@email.com" cc="email@email.com" subject="freshman.#DateFormat(Now(),'mmddyy')#.txt" mimeattach="filepath\freshman.#DateFormat(Now(),'mmddyy')#.txt">Your freshman catalog requests</cfmail>
0
rragledavis
Asked:
rragledavis
  • 2
  • 2
1 Solution
 
pmascariCommented:
I ran into a similar problem and found the issue was the CFSAVECONTENT tag.  For some reason it was putting in hidden line break characters.  The only way I got around it was to use something else.  It's a great tag, but when you need to be precise in making delimited files it doesn't seem to be up to the task.

Maybe something like this will work instead:

<cfset admissions_file= "">

<cfloop query="freshman">
  <cfset admissions_file= "#Title#" & chr(9)>
  <cfset admissions_file= "#Name#" & chr(9)>
  <cfset admissions_file= "#Middle#" & chr(9)>
  <cfset admissions_file= "#Last#" & chr(9)>
  <cfset admissions_file= "#Address#" & chr(9)>
  <cfset admissions_file= "#Address2#" & chr(9)>
  <cfset admissions_file= "#City#" & chr(9)>
  <cfset admissions_file= "#State#" & chr(9)>
  <cfset admissions_file= "#Zip#" & chr(9)>
  <cfset admissions_file= "#Country#" & chr(9)>
  <cfset admissions_file= "#Email#" & chr(9)>
  <cfset admissions_file= "#Interest#" & chr(9)>
  <cfset admissions_file= "#Year#" & chr(9)>
  <cfset admissions_file= "#Date#" & chr(9)>
  <cfset admissions_file= "#ID#" & chr(9)>
  <cfset admissions_file= "#Degree#" & chr(10)>
</cfloop>

<cffile action="write" output="#admissions_file#" file="filepath\freshman.#DateFormat(Now(),'mmddyy')#.txt" nameconflict="overwrite">
0
 
rragledavisAuthor Commented:
Just tried and this just resets the value of admissions_file over and over until the last field of the last record so my data set ends up UG? Oh well. . .
0
 
pmascariCommented:
Oops...forgot one important piece of info:

<cfset admissions_file= "">

<cfloop query="freshman">
  <cfset admissions_file= admissions_file & "#Title#" & chr(9)>
  <cfset admissions_file= admissions_file & "#Name#" & chr(9)>
  <cfset admissions_file= admissions_file & "#Middle#" & chr(9)>
  <cfset admissions_file= admissions_file & "#Last#" & chr(9)>
  <cfset admissions_file= admissions_file & "#Address#" & chr(9)>
  <cfset admissions_file= admissions_file & "#Address2#" & chr(9)>
  <cfset admissions_file= admissions_file & "#City#" & chr(9)>
  <cfset admissions_file= admissions_file & "#State#" & chr(9)>
  <cfset admissions_file= admissions_file & "#Zip#" & chr(9)>
  <cfset admissions_file= admissions_file & "#Country#" & chr(9)>
  <cfset admissions_file= admissions_file & "#Email#" & chr(9)>
  <cfset admissions_file= admissions_file & "#Interest#" & chr(9)>
  <cfset admissions_file= admissions_file & "#Year#" & chr(9)>
  <cfset admissions_file= admissions_file & "#Date#" & chr(9)>
  <cfset admissions_file= admissions_file & "#ID#" & chr(9)>
  <cfset admissions_file= admissions_file & "#Degree#" & chr(10)>
</cfloop>

Sorry for the confusion.
0
 
8riaNCommented:
Hmm, if it consistently adds a blank line, could you just depend on that and take out your carriage return and use the one it's adding?

Like this:
<cfsetting enablecfoutputonly="yes"></head><body><cfsavecontent variable="admissions_file"><cfloop query="freshman"><cfoutput>"#Title#"     "#Name#"     "#Middle#"     "#Last#"     "#Address#"     "#Address2#"     "#City#"     "#State#"     "#Zip#"     "#Country#"     "#Email#"     "#Interest#"     "#Year#"     "#Date#"     "#ID#"     "#Trim(Degree)#"</cfoutput></cfloop></cfsavecontent>

Personally, I'd do this instead:
<cfset filename="filepath\freshman.#DateFormat(Now(),'mmddyy')#.txt">

(if you need the first line to have field names)
<cfset headers="Title     Name     Middle     Last     Address     Address2     City     State     Zip    Country     Email     Interest     Year     Date     ID     Degree">
<cffile action="WRITE" file="#filename#" output="headers" addnewline="Yes">

then the content
<cfloop query="freshman">
   <cfset outputLine="#Title#     #Name#     #Middle#     #Last#     #Address#     #Address2#     #City#     #State#     #Zip#    #Country#     #Email#     #Interest#     #Year#     #Date#     #ID#     #Degree#"> <!--- where the whitespace is the single tab delimiter. --->
   <cffile action="APPEND" file="#filename#" output="outputLine" addnewline="Yes">
</cfloop>
0
 
rragledavisAuthor Commented:
pmascari That worked. Wonderful!

8riaN I had either a choice of two carriage returns or none. Either one continuous record or a blank between each record so couldnt count on one being added
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now