我想打开带有“另存为”选项的PDF文件,该选项在代码下方无法正常下载PDF文件
下面是cod eon handler.asp文件。我希望将文件名传递为querystring
,在这种情况下,我在代码中使用静态文件名。
是代码示例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
public partial class en_PdfHandler : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string filename = Request.QueryString["fn"];
string path = Server.MapPath("1.pdf");
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(path);
if (buffer != null)
{
Response.ClearContent();
Response.ClearHeaders();
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=1.pdf");
Response.AddHeader("Content-Length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
Response.End();
Response.Flush();
Response.Close();
}
}
}
}