Urbycoz
Urbycoz

Reputation: 7421

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 />

Is there an equivalent method for downloads?

Upvotes: 0

Views: 3381

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

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

Upvotes: 2

Related Questions