How to Download Secure Statement

J

JJ

Hi,

I have written a web app in asp3 which is used by lots of users.
The data is all held server side.
However, I want it so that the users can export the data in a csv file, much
like you can download a statement from online banking.

However, I don't want to save the file to the server, as then anyone else
might guess the filename and download it.
Is there any way to directly generate a file from an asp script. i.e.
instead of asp returning html, it returns csv data which the user can save
away.

Many Thanks in Advance

JJ
 
D

Don Grover

Here is a function that exports a csv or tab delimited using adodb stream..
It enumerates fields in a db so does not need much conversion
<%
'We got this far so validation is acheived
fncExportStockUnits SQLtemp, SQLFrom, SQLWhere, SQLOrder
%>
<%
Sub fncExportStockUnits(TheSQLtemp,TheSQLFrom,TheSQLWhere,TheSQLOrder)
Set orsExp = Server.CreateObject("ADODB.Recordset")
orsExp.cursorlocation = adUseClient
orsExp.open TheSQLtemp & TheSQLFrom & SQLWhere & TheSQLOrder, oconn,
adOpenForwardOnly, adLockReadOnly, adCmdText
For iFldCount = 0 To orsExp.Fields.Count - 1
sColName = sColName & LCase(orsExp(iFldCount).Name) & ","
Next
sHeader = "rec_num" & sDelimiter & Left(sColName, Len(sColName) - 1)
' If there is data in the result set...
If Not orsExp.EOF Then
nFields = orsExp.Fields.Count - 1 ' Determine the number of
fields in the result set for later
' Loop through the result set
While Not orsExp.EOF
sOut = "" ' Initialize the output string
' Create a string that contains a delimited value for each field
returned in the recordset.
' Doing this way allows you to pass any recordset to this loop
For x = 0 To nFields
' Here we test to see if this field is one that we want
surrounded by quotes
' For our purposes, we will do this for Text and Dates
If orsExp.Fields(x).Type = 202 Then
sOut = sOut & sQuoteType & orsExp(x) & sQuoteType &
sDelimiter
ElseIf orsExp.Fields(x).Type = 135 Then
sOut = sOut & sQuoteType &
getDateFormated(orsExp(x),sDateFormat) & sQuoteType & sDelimiter
ElseIf orsExp.Fields(x).Type = 6 Then
varTmp = orsExp(x)
If ISNULL(varTmp) Then
varTmp = 0 'Fix for null fields from DTM Update
End If
sOut = sOut & sQuoteType & FormatNumber(varTmp,2) &
sQuoteType & sDelimiter
Else ' No quotes are required...
sOut = sOut & orsExp(x) & sDelimiter
End If
Next
iCount = iCount + 1
' There are more elegant ways to strip the last sDelimiter but...
sOut = iCount & sDelimiter & Left(sOut, Len(sOut) - 1) & vbCrLf
sExport = sExport & sOut
orsExp.MoveNext ' Read in the next record in the
result set
Wend
End If
' Clean up
orsExp.Close
Set orsExp = Nothing
'Set the content type to the specific type that you are sending.
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.ContentType = "text/csv"
Response.ContentType="application/csv"
Response.AddHeader "Content-Disposition", "filename=" &
sExportFileName & ";"
Response.write sHeader & vbCrLf & sExport
End Sub
%>
 

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

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,371
Latest member
Brkaa

Latest Threads

Top