Forcing a file download w/ a button

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
 
W

William LaMartin

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top