Forum Moderators: open
I have an admin area where I (or a colleague) can login to and view the orders etc.
I want to use this interface to download today's orders locally in the format of a text file such as CSV.
Can anyone tell me how I can write the output from an SQL query into a text file, then recieve a prompt to download it.
I can decrypt the encrypted data later, but ideally, I'd like to decrypt it first before downloading. I don't, however want any unencrypted data getting left on the server.
Thanks, Al
- Create your query, and get your dataset/recordset
- Clear the Response Output
- Set the ContentType of the Response to be "text/csv"
- Add a Response Header that is "Content-disposition", "filename=yourexport.csv"
- Write your dataset/recordset to the Response Output, formatted properly for the CSV file.
<%
' export.asp
response.ContentType="application/vnd.ms-excel"
dim objConn, strSQL
set objConn=Server.CreateObject("ADODB.Connection")
openDB( objConn )
strSQL = Sanitise(Request("SQL"))
set objRS=objConn.Execute ( strSQL )
if err.number <> 0 then
raiseError 126, "SQL Provider", "Invalid SQL"
end if
dim i,x
Response.Write "<h3>" & Request("Title") & "</h3>"
Response.Write "<table><tr>"
for each x in objRS.Fields
Response.Write "<td>" & x.name & "</td>"
next
Response.Write "</tr>"
while not objRS.eof
Response.Write "<tr>"
for each x in objRS.Fields
Response.Write "<td>" & x.value & "</td>"
next
Response.Write "</tr>"
objRS.MoveNext
wend
Response.Write "</table>"
closeRS(objRS)
closeDB(objConn)
%>
I'm using this to output the data to file...
Response.Clear
Response.AddHeader "Content-disposition","attachment;filename=data.txt"
What code do I add which will output the HTML code to the browser.