Choose file download location
I need to allow users to download a file to their machine in my vb.net web app. I need them to browse to the download location themselves through some kind of navigation window.
For uploads I simply use a type="file"
:
<input type="file" value="upload />开发者_Python百科
Is there an equivalent method for downloads?
For downloads you usually create a link:
<asp:LinkButton ID="DownloadButton" runat="server" Text="Download report" OnClick="BtnDownloadClick" />
and in the code behind you stream the file to the response:
Protected Sub BtnDownloadClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DownloadButton.Click
Response.ContentType = "application/pdf"
Response.AppendHeader("Content-Disposition", "attachment; filename=report.pdf")
Response.Clear()
Response.WriteFile(Server.MapPath("~/report.pdf"))
End Sub
精彩评论