CSV Download

S

Simon Harris

Hi All,

I have created a script which connects to a SQL DB, runs a query, writes the
results out to a file (Using FSO) then presents the user with a link to
download the CSV.
As the file contains sensitive data, I dont want to leave the file on the
server, and I dont want to rely on the user to delete the file after every
export.

Does anyone have any suggestions?

Thanks,
Simon.
 
M

Manohar Kamath

Why not stream the contents of the file, instead of creating a file and
letting the user download it? So, instead of writing using FSO, you write it
out to the response object. Just make sure you change the content type to
reflect the CSV download:

<%
Response.ContentType = "text/csv"
%>
 
R

Ray Costanzo [MVP]

Yes, do not ever create the file! :]

<%
set oADO = CreateObject("ADODB.Connection")
oADO.Open YourConnectionSTring

Set oRS = oADO.Execute("Your query")
sCSV = oRS.GetString(2,,",",vbCrLf,"")
oRS.Close : Set oRS = Nothing
oADO.Close : Set oADO = Nothing

Response.ContentType = "Simon's CSV File"
Response.AddHeader "Content-Disposition","attachment;
filename=sensitiveData.csv"
Response.Write sCSV
%>

Ray at work
 
S

Simon Harris

Thanks Manohar, sounds like a good idea - I guess I would create the CSV in
memory by building a string, then pump it all to the browser?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top