显示保存文件对话框中asp.net [英] Showing Save file dialog box in asp.net

查看:171
本文介绍了显示保存文件对话框中asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在asp.net中。
我参考了用户的输入创建PDF文件。
本PDF文件保存在文件夹上服务器。
现在,这是文件可以在浏览器中使用的Response.Redirect显示。
但我想,以显示保存文件对话框(如我们得到在从网站下载EXE)用户下载并保存在本地硬盘相同的文件,而不是在浏览器中打开它。
我怎样才能做到这一点?

This is in asp.net. I am creating pdf file with reference to the inputs from users. This pdf file is saved on folder on server. Now this is file can be shown in browser using response.redirect. But I want to show the Save file dialog (like we get while downloading exe from websites) to the user for downloading and saving the same file in local hard disk instead of opening it in browser. How can i do that??

推荐答案

设置 Response.ContentType =应用程序/八位字节流; 通常为我工作。我还用 Response.BinaryWrite 为好。有一个MIME类型应用程序/ PDF MIME类型检测在Windows Internet Explorer ),所以你可以给一个尝试了。

Setting Response.ContentType = "application/octet-stream"; usually works for me. I also use Response.BinaryWrite as well. There IS a mime type application/pdf (MIME Type Detection in Windows Internet Explorer), so you might give that a try too.

下面是一个使用一个例子应用程序/ PDF 微软(的如何写入二进制文件浏览器中使用ASP.NET和Visual C#.NET

Here's an example using application/pdf from Microsoft (How To Write Binary Files to the Browser Using ASP.NET and Visual C# .NET)

private void Page_Load(object sender, System.EventArgs e)
{
  //Set the appropriate ContentType.
  Response.ContentType = "Application/pdf";
  //Get the physical path to the file.
  string FilePath = MapPath("acrobat.pdf");
  //Write the file directly to the HTTP content output stream.
  Response.WriteFile(FilePath);
  Response.End();
}

这篇关于显示保存文件对话框中asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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