Display Download Dialog with asp.net vb



Display Download Dialog with asp.net vb If you have files and their locations that you would like to keep secury hidden, or you have files such as mpegs that usually play when you click a hyperlink, you can use the below code to automatically display the download dialog box.
Dim eFile As System.IO.FileInfo
eFile = New System.IO.FileInfo(Server.MapPath("/downloads/filename.ext"))
Response.Clear()
Response.AddHeader("Content-Length", objFile.Length.ToString())
Response.AddHeader("Content-Disposition", "attachment;filename=filename_you_want_to_call_download.ext")
Response.ContentType = "application/octet-stream"
Response.WriteFile(eFile.FullName)
Response.Flush()
Response.End()
All you need to do is change the path to the file above, I've entered '/downloads/filename.ext' as an example and you will also have to change 'filename_you_want_to_call_download.ext' to what ever you want the person downloading to be prompted to save the file as. This protentially could be a totally different file name and that therefore adds more security to your files locations etc.


Send a link to this page via email Send a link to this page via email