2011-05-31 85 views
0

我需要允许用户在我的vb.net web应用程序中将文件下载到他们的机器。我需要他们通过某种导航窗口浏览下载位置。选择文件下载位置

对于上载我简单地用一个type="file"

<input type="file" value="upload /> 

是否有下载等效的方法?

+0

你能解释一下你的问题一点? 你的意思是说你想让用户下载文件,但想显示“保存”对话框,这将允许用户选择位置保存在本地机器上? – 2011-05-31 07:36:11

+0

不是。我想要一个更一般的文件浏览窗口,它只是让用户看到他们自己的驱动器并选择一个特定的位置。一旦选择,我想自己使用这条路径来使用我自己定制的保存方法。 – Urbycoz 2011-05-31 08:16:18

回答

2

对于下载您通常会创建一个链接:

<asp:LinkButton ID="DownloadButton" runat="server" Text="Download report" OnClick="BtnDownloadClick" /> 

在你身后的码流文件的响应:

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