filePath是文件的路径,filename是文件名,下面是可以下载PDF文件,但是下载后,是找不开的,说是损坏或不支持的文件类型,请问大家在提供PDF下载时,是怎样输出PDF文件的呀!
FileStream fs = new FileStream(filePath, FileMode.Open,FileAccess.Read ,FileShare.ReadWrite);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
ApplicationInstance.CompleteRequest();
fs = null;
Baidu一下,你就知道:
PDF格式的文件Response.ContentType应该等于“Application/PDF".