选择用户计算机上的下载位置

时间:2012-02-21 08:12:42

标签: c# asp.net c#-4.0

我有一个asp.net网站。它是用户和sftp服务器之间的接口。这意味着我在sftp服务器中有文件。我将用户想要的文件直接下载到用户计算机而不存储具有网站代码的服务器。

我需要一个小窗口,让用户选择下载存储在sftp服务器中的文件的位置。

我该怎么办?谢谢..

3 个答案:

答案 0 :(得分:1)

如果您只想要“保存文件”对话框,则可以在回复中添加标题。

Response.AppendHeader("content-disposition", "attachment; filename=whatever.txt");
Response.ContentType = "application/octet-stream";

您可以不设置ContentType,也可以根据需要将其设置为特定的MIME类型。

答案 1 :(得分:0)

为响应添加特殊标题以强制浏览器显示save-file-dialog,例如:

Response.AppendHeader("content-disposition", "attachment; filename=" + name);

答案 2 :(得分:0)

试试这个:

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

这将提示“打开/另存为”对话框。

有关详细信息:http://www.west-wind.com/weblog/posts/2007/May/21/Downloading-a-File-with-a-Save-As-Dialog-in-ASPNET