When PDF files are downloaded, the user receives the following error:
"There was an error opening this document. The file is damaged and could not be repaired".
This error occurs with older versions of Adobe Acrobat Reader (tested and failed on 6.0, 7.0). The code I am using is pasted below and is a collaboration of research I've done on EE and google.
Note: The file that is streamed to the user has a higher file size than the actual file. You can see below I have tried using different headers, pdf and octet-stream.
We must maintain the ability of allowing the client to download the pdf file rather than it opening in the browser.
Any help is appreciated.
FileStream objfilestream = new FileStream(@"C:\MFiles\" + Session["FilePath"].ToString(), FileMode.Open, FileAccess.Read);
int FileSize = (int)objfilestream.Length;
byte getContent = new byte[FileSize];
objfilestream.Read(getContent, 0, FileSize);
Response.AddHeader("content-disposition", "attachment; filename=" + Session["FilePath"].ToString());
//Response.ContentType = "application/pdf";
Response.ContentType = "application/octet-stream";