Downloading a CSV from IE

snooper

Perch
Hey there

I have a script that should wonload a CSV file from the browser. It works perfectly on Firefox and Chrome - but on IE(v7) it chokes and throws and error - "IE was not able to download the file..."

any idea what it could be?
ASP code attached.

thanks!


Code:
<%
sql = "SELECT ...."
set rs = conn.execute(sql)
 
if rs.eof then
	response.Write("No data available in this table")
	set rs = nothing
else
	strReturn = ""
	for each field in rs.fields
		strReturn = strReturn & field.name & ","
	next
	strReturn = left(strReturn, len(strReturn)-1)	'remove last comma
	strReturn = strReturn & vbcr 
 
	do while not rs.eof
		for each field in rs.fields
			
			fieldvalue = rs.fields(field.name) & ""
			fieldvalue = replace(fieldvalue, ","," ")
			fieldvalue = replace(fieldvalue, "","'")
			fieldvalue = replace(fieldvalue, """","'")
			fieldvalue = replace(fieldvalue, "","'")
			fieldvalue = replace(fieldvalue, "="," ")
			
			fieldvalue = replace(fieldvalue, vbCrLf," ")
			fieldvalue = replace(fieldvalue, vbCr," ")
			fieldvalue = replace(fieldvalue, chr(10)," ")
			fieldvalue = replace(fieldvalue, chr(13)," ")
					
			strReturn = strReturn & chr(34) & fieldvalue & chr(34) &  ","
		next
		strReturn = left(strReturn, len(strReturn)-1)	'remove last comma
		strReturn = strReturn & vbCrLf
		rs.movenext
	loop
 
 
 
	rs.Close
	set rs = Nothing
	
	server.ScriptTimeout = 18000
	 
	Response.AddHeader "Content-Disposition", "attachment; filename=report-" & request.Cookies(ewProjectName)("programID") & "-" & exportTable&".csv"
 
	Response.Charset = "UTF-8"
	Response.ContentType = "text/csv"	
	Response.Write  strReturn
	Response.Flush
	Response.Clear
 
%>
 
Hmm, I don't see anything that would make it break in IE specifically. Incidentally I hacked up a quick CSV download in .NET today and it works fine in IE. Headers sent are similar (I just don't set the character set).

It might just be mangling from pasting your code, but it seems you're trying to replace an empty string with a single quotation mark? I doubt that would do anything, if it did, you'd end up with an infinite length string or something :)
 
hey there!

thanks for the reply.
its just so weird - that it works in FF and not in IE. i assume it means its a mime issue or something.

re the single quote replace - you are right - it dint paste properly - its one of those funny MS-WORD quote marks that i am removing.

thanks again!
 
Back
Top