如何下载提交/创建的pdf文件?

时间:2013-05-15 03:25:22

标签: c# asp.net

我想要替换>>>> Response.WriteFile(FilePath);<<<<使用将下载pdf文件的代码。

LinkButton lnk = (LinkButton)sender;
if (lnk != null)
{
    Response.ContentType = "Application/pdf";
    string entry = lnk.CommandName;
    string FilePath = _FilePath + GetFolderName(entry) + lnk.CommandArgument.ToString();
    Response.WriteFile(FilePath); 
    Response.End();
}

提前谢谢! :d

3 个答案:

答案 0 :(得分:1)

尝试使用此标头application/octet-stream代替application/pdf

答案 1 :(得分:1)

你还需要追加标题

Response.ContentType = "Application/pdf"; 
Response.AppendHeader("Content-Disposition", "attachment; filename=YourFileName.pdf"); 
Response.TransmitFile(Server.MapPath("~/Files/YourFileName.pdf")); 
Response.Flush() 
Response.End();

答案 2 :(得分:0)

FileInfo fi = new FileInfo(@Request.PhysicalApplicationPath + File_Name);//
long sz = fi.Length;
Response.ClearContent();
Response.ContentType = MimeType(Path.GetExtension(File_Name));
Response.AddHeader("Content-Disposition", string.Format("attachment; filename = {0}", System.IO.Path.GetFileName(File_Name)));
Response.AddHeader("Content-Length", sz.ToString("F0"));
Response.TransmitFile(File_Name);
Response.End();