2011-04-25 24 views
1

我在asp.net中使用vb.net脚本编写的应用程序生成一个带有系统处理输出的文件,响应按钮单击。该文件存储在服务器中的一个文件夹中,我想要为用户自动下载此文件。我该怎么做?如何在asp.net中自动提示文件下载?

回答

2

以下代码将向用户显示标准的“另存为..”对话框。您需要将内容类型更改为MIME文件。

Response.ContentType = "image/jpeg"; 
Response.AppendHeader("Content-Disposition","attachment; filename=yourfile.jpg"); 
Response.TransmitFile(Server.MapPath("~/yourfile.jpg")); 
Response.End(); 
+0

太好了。工作正常。谢谢! – Alex 2011-04-26 20:04:48