我想要替换>>>> 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
答案 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();