0

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

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

4

3 回答 3

1

试试这个标题application/octet-stream而不是application/pdf

于 2013-05-15T03:31:39.830 回答
1

您还需要附加标题

Response.ContentType = "Application/pdf"; 
Response.AppendHeader("Content-Disposition", "attachment; filename=YourFileName.pdf"); 
Response.TransmitFile(Server.MapPath("~/Files/YourFileName.pdf")); 
Response.Flush() 
Response.End();
于 2013-05-15T03:34:36.963 回答
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();
于 2013-05-15T05:48:44.960 回答