473,414 Members | 1,628 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Some File Types pulled from Image field corrupted when using Response.BinaryWrite() to download...

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
Nov 19 '05 #1
1 2872
I am using vb.net and I have got it working uploading and retrieving files
into an image datatype. The only type I havent got to work is pdf.

Here is my code:
' Uploading
fLen = myFile.ContentLength

Dim fBuffer(fLen) As Byte

myFile.InputStream.Read(fBuffer, 0, fLen)

' myFile is of type HttpPostedFile
dr("mcontent") = fBuffer

dr("ilength") = fLen

'Downloading

dr = dt.Rows(0)

Dim fBuffer(dr("ilength")) As Byte

fBuffer = dr("mcontent")

Response.ContentType = dr("cContentType")

'Response.ContentType = "application/octet-stream"

Response.AddHeader("Content-Disposition", _

"attachment; filename=" & dr("cfilename"))

Response.OutputStream.Write(fBuffer, 0, dr("ilength")

I hope this helps

"Charlie@CBFC" <ch*****@comcast.net> wrote in message
news:eB**************@TK2MSFTNGP15.phx.gbl...
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

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: kee | last post by:
Hi All, I am trying to write binary data to a file, which is bmp image: Open "d:\temp\test001.bmp" For Binary Access Write As #1 Put #1, 1, strImage Close #1 *** strImage contains binary...
2
by: RickL | last post by:
I have an ASP application that uploads a specified file to the server. To retrieve the file, I simply assign the filepath and file to a hyperlink on the page. When you click "Save Target As" for...
8
by: dave | last post by:
Hi there I'm trying to force save as dialogue using this code in download.asp..but when it runs it prompts for download.asp to save or open. code snippet (from aspfaq.com) ...
5
by: Baren | last post by:
Hi! I am using impersonate="true" to upload and download files from a network share. I have created common users on both the webserver and the file server. The user has permission to the...
0
by: JD | last post by:
Hello Everyone, I am trying to set up a media kit page where when a user comes to the page for the first time and click on the image they wish to download they are brought to a registration...
1
by: Bala | last post by:
Hi I try to download the tiff files from my server. Its get downloaded but I cannot open with windows fax viewer. its says "No preview available" thanks bala here is the code which I am...
3
by: David Thielen | last post by:
Hello; When I get a request for a page, how can I return a pdf as the page contents? In java the way to do this is for the response set it's type to "application/pdf" and then get a byte (not...
17
by: mansb2002 | last post by:
Hi, We recently moved our webserver from Win2K to Win2003. The application works fine. Only problem is that when user views a report as a PDF, IE does not show it. The following code is used to...
4
by: =?Utf-8?B?U1VOTlk=?= | last post by:
Hi, i am uploading a .docx file into sql2005 and later when i retrieve the file from the database and i open it, i get a error message "The file is corrupted and cannot be open". I am not facing...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.