Angel Filev wrote:
> Hi everyone,
> I am trying to store a file as a binary array in an "image" field in
> SQL Server 2000 database. It works OK except for the ".PDF" files,
> which I believe get corrupted in the process of reading a stream to a
> byte array. Uploading and downloading seems to work fine, but
> "Acrobat" pop ups "The file is damaged and could not be repaired"
> error. Is there any way I can make this to work.
>
> Following is a pseudo code of what I am trying to accomplish.
>
> //Uploading a file browser->web server
> //get file size (theFile is a VS "file field" component )
> int fileSize = theFile.PostedFile.ContentLength;
> //get file as binary stream
> Stream fileStream = theFile.PostedFile.InputStream;
> //create byte array to keep file as bytes
> byte[] bArray = new byte[fileSize];
> //load array from stream
> fileStream.Read(bArray , 0, size);
> //At this point bArray is saved to DataBase
>
> //Downloading file
> //read image field from database and typecast as byte array
> byte [] bArray = GetBinaryArrayFromDB()
> string fileName = GetFileName();
> string fileType = GetMIMEFileType();
>
> //Send file to the browser
> Response.AddHeader("Content-Disposition", "attachment; filename=" +
> fileName); Response.ContentType = fileType;
> Response.BinaryWrite(bArray);
Your not-so-pseudo-code looks ok
What happens if you set a Content-Length header with the value of
bArray.Length? Older Acrobat plugins require Content-Length.
Cheers,
--
http://www.joergjooss.de
mailto:news-