Vis*_*hal 1 vb.net asp.net download text-files
我想从我的网站下载文本文件到用户PC而不提示他输入文件的位置.
我使用下面的代码尝试过它:
Response.TransmitFile("G:\Medical Reporting\Medical\Users\Vishal\Uploaded\Key.txt")
Response.End()
Run Code Online (Sandbox Code Playgroud)
但每次我被重定向到新页面,文件的所有内容都写在那里.我不想显示文件的内容,但我想下载该文件.
不可能 - 这是一个安全问题,否则全世界都会试图在用户机器上保存各种文件.
如果是内联网,则每个用户都可以在Web应用程序可访问的网络上拥有共享驱动器,只需使用IO.File.Copy方法复制该文件即可.
更新
要提示用户下载文件,您可以使用以下代码,在单击按钮之后将触发该代码:
此示例适用于图像,但您可以更改ContentType文件名以满足您的需要.
Response.ContentType = "image/jpeg";
// this is the important bit that gives the user the prompt to save
Response.AppendHeader("Content-Disposition","attachment; filename=yourfile.jpg");
Response.TransmitFile(Server.MapPath("~/yourfile.jpg"));
Response.End();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4287 次 |
| 最近记录: |