【问题标题】:Choose file download location选择文件下载位置
【发布时间】:2011-05-31 07:29:08
【问题描述】:

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

对于上传,我只需使用 type="file"

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

是否有等效的下载方法?

【问题讨论】:

  • 你能解释一下你的问题吗?你的意思是说你想允许用户下载文件但想显示“保存”对话框,允许用户选择保存在本地机器上的位置?
  • 并非如此。我想要一个更通用的文件浏览窗口,它只允许用户查看自己的驱动器并选择特定位置。选择后,我想自己使用此路径以用于我自己的自定义保存方法。

标签: asp.net vb.net download


【解决方案1】:

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

<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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-24
    • 1970-01-01
    • 2011-08-11
    相关资源
    最近更新 更多