开发者

Choose file download location

开发者 https://www.devze.com 2023-03-09 16:21 出处:网络
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.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消