How to Download Secure Statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JJ

    How to Download Secure Statement

    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


  • Don Grover

    #2
    Re: How to Download Secure Statement

    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
    fncExportStockU nits SQLtemp, SQLFrom, SQLWhere, SQLOrder
    %>
    <%
    Sub fncExportStockU nits(TheSQLtemp ,TheSQLFrom,The SQLWhere,TheSQL Order)
    Set orsExp = Server.CreateOb ject("ADODB.Rec ordset")
    orsExp.cursorlo cation = adUseClient
    orsExp.open TheSQLtemp & TheSQLFrom & SQLWhere & TheSQLOrder, oconn,
    adOpenForwardOn ly, adLockReadOnly, adCmdText
    For iFldCount = 0 To orsExp.Fields.C ount - 1
    sColName = sColName & LCase(orsExp(iF ldCount).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.C ount - 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),sDat eFormat) & 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(va rTmp,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.AddHea der "pragma","n o-cache"
    Response.AddHea der "cache-control","priva te"
    Response.Conten tType = "text/csv"
    Response.Conten tType="applicat ion/csv"
    Response.AddHea der "Content-Disposition", "filename=" &
    sExportFileName & ";"
    Response.write sHeader & vbCrLf & sExport
    End Sub
    %>



    "JJ" <nospam> wrote in message
    news:4030eedf$0 $9750$cc9e4d1f@ news.dial.pipex .com...[color=blue]
    > 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,[/color]
    much[color=blue]
    > 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
    >
    >[/color]


    Comment

    Working...