c# - PDF File Corrupt After Serving file over HTTP -


so have pdf file on server, can open , looks fine.

i try serve file code

response.contenttype = "application/pdf"; response.appendheader("content-disposition", "attachment; filename=filename.pdf"); response.transmitfile("c:\\temp\\filename.pdf"); response.end(); 

this serves file, saves on client, problem new file .05mb larger original, , when try open pdf corrupt.

any ideas?

your code should work. please make sure using ajax downloading file.

you can try using flash , close before end.

response.contenttype = "application/pdf"; response.appendheader("content-disposition", "attachment; filename=filename.pdf"); response.transmitfile("c:\\temp\\filename.pdf"); response.flush(); response.close(); response.end(); 

if still doesn't work, can try binarywrite. disadvantage doesn't work large file because loads file memory before sending client.

response.contenttype = "application/pdf"; response.addheader("content-disposition", "attachment; filename=filename.pdf")); response.binarywrite(file.readallbytes("c:\\temp\\filename.pdf")); response.end();