Topic: Save As dialog for text file
I want to be able to allow a user at my site to download a text file to their local machine. They should be presented with a save as dialog. I found this code here below. My question is how do I get the filename and path to this sub? I tried a couple of hyperlinks, but they are not working for me. They don't do anything when clicked and the browser doesn't allow the file to open up and be saved. I'm using a gridview. Should I create a button and code each button with a path to the file and a filename? Is it possible to set these as command args in the code behind so when the user clicks the button these paramaters are passed into this sub here and the user is served up a save as dialog?
Public Sub DownloadFile()
Dim FileName As String = ""
Dim FilePath As String = ""
'Dim FilePath As String = AppDomain.CurrentDomain.BaseDirectory & "/App_Data/Uploads/" + FileName
Dim response As System.Web.HttpResponse = System.Web.HttpContext.Current.Response
response.ContentType = "text/plain"
response.AddHeader("Content-Disposition", "attachment; filename=" & FileName & ";")