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>
rragledavisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.