选择文件下载位置 [英] Choose file download location

查看:199
本文介绍了选择文件下载位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

有关下载你通常会创建一个链接:

For downloads you usually create a link:

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

和在你身后的code流文件到响应:

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

这篇关于选择文件下载位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆