C
Charlie@CBFC
Hi:
I'm uploading documents into a SQL Server Image field and using
Response.BinaryWrite() to download or view them in the browser. Some doc
types like Adobe Illustrator and Photoshop files will open correctly, but
other like Word, Excel and Powerpoint are corrupt. Here is code fragment to
upload:
// Get file in byte array
int fileLen = this.TextBoxFileToUpload.PostedFile.ContentLength;
byte[] arrayFile = new byte [fileLen];
Stream strm = this.TextBoxFileToUpload.PostedFile.InputStream;
string contentType = this.TextBoxFileToUpload.PostedFile.ContentType;
strm.Read(arrayFile, 0, fileLen);
// Run insert commands...
Here is download code fragment:
// Get data into a reader...
// write to browser
Response.ContentType = reader["ContentType"].ToString();
Response.AppendHeader("Content-Disposition", "attachment; filename = " +
fileName);
Response.BinaryWrite((byte[]) reader["FileContents"]);
Should work, seems like I'm missing something.
Thanks,
Charlie
I'm uploading documents into a SQL Server Image field and using
Response.BinaryWrite() to download or view them in the browser. Some doc
types like Adobe Illustrator and Photoshop files will open correctly, but
other like Word, Excel and Powerpoint are corrupt. Here is code fragment to
upload:
// Get file in byte array
int fileLen = this.TextBoxFileToUpload.PostedFile.ContentLength;
byte[] arrayFile = new byte [fileLen];
Stream strm = this.TextBoxFileToUpload.PostedFile.InputStream;
string contentType = this.TextBoxFileToUpload.PostedFile.ContentType;
strm.Read(arrayFile, 0, fileLen);
// Run insert commands...
Here is download code fragment:
// Get data into a reader...
// write to browser
Response.ContentType = reader["ContentType"].ToString();
Response.AppendHeader("Content-Disposition", "attachment; filename = " +
fileName);
Response.BinaryWrite((byte[]) reader["FileContents"]);
Should work, seems like I'm missing something.
Thanks,
Charlie