Posted on: 2/29/2012 6:15:35 AM | Views : 946

I have a document uploader on my project. Everything works fine except docx documents on download. I am told this is because when storing a binary file in SQL Server a file is padded to the nearest boundry, so you can potentially have an extra byte added to a file. The solution is to store the original file size in the db when you store the file, and use that for the length that needs to be passed to the write function of the Stream object. "This is the ONLY reliable way of getting the correct file size, which is very important for XML Office 2007 and up files, which do not allow extra characters to be on the end of them (most other file types like jpg's don't care)."

This is all very good stuff and I have now changed my database so that it holds and uploads the file size into an unimaginatively named field called FileSize.

Problem being... How do I download it using the stored file size?

The following code is my download script which does down ...

Go to the complete details ...