Forcing a file download w/ a button

  • Thread starter Thread starter Do
  • Start date Start date
D

Do

Hi,

My issue is twofold.

1) How do I invoke a "save file" action when a user clicks a button.
In classic ASP, I used to response.redirect to file path. But I want
to keep the user on the same page they clicked "Download" button.

2) How do I force to prompt for a save file when the user clicks the button
rather than try to open and read the file in the browser, which is the
default action.

Thanks,

Do
 
This may do what you want (here file names for download are listed in a
radio button list)

Dim filepath As String
Dim filename As String
If Me.RadioButtonList1.SelectedIndex <> -1 Then
filename =
Me.RadioButtonList1.Items(Me.RadioButtonList1.SelectedIndex).Text
filepath = Server.MapPath(".") & "\downloads\" & filename
Else
Exit Sub
End If
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", _
"attachment; filename=""" & filename & """")
Response.WriteFile(filepath)
 

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

Back
Top