473,698 Members | 2,149 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Hi:

I'm uploading documents into a SQL Server Image field and using
Response.Binary Write() 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.TextBoxFil eToUpload.Poste dFile.ContentLe ngth;
byte[] arrayFile = new byte [fileLen];
Stream strm = this.TextBoxFil eToUpload.Poste dFile.InputStre am;
string contentType = this.TextBoxFil eToUpload.Poste dFile.ContentTy pe;
strm.Read(array File, 0, fileLen);

// Run insert commands...

Here is download code fragment:

// Get data into a reader...

// write to browser
Response.Conten tType = reader["ContentTyp e"].ToString();
Response.Append Header("Content-Disposition", "attachment ; filename = " +
fileName);
Response.Binary Write((byte[]) reader["FileConten ts"]);

Should work, seems like I'm missing something.

Thanks,
Charlie
Nov 19 '05 #1
1 2915
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.ContentL ength

Dim fBuffer(fLen) As Byte

myFile.InputStr eam.Read(fBuffe r, 0, fLen)

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

dr("ilength") = fLen

'Downloading

dr = dt.Rows(0)

Dim fBuffer(dr("ile ngth")) As Byte

fBuffer = dr("mcontent")

Response.Conten tType = dr("cContentTyp e")

'Response.Conte ntType = "applicatio n/octet-stream"

Response.AddHea der("Content-Disposition", _

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

Response.Output Stream.Write(fB uffer, 0, dr("ilength")

I hope this helps

"Charlie@CB FC" <ch*****@comcas t.net> wrote in message
news:eB******** ******@TK2MSFTN GP15.phx.gbl...
Hi:

I'm uploading documents into a SQL Server Image field and using
Response.Binary Write() 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.TextBoxFil eToUpload.Poste dFile.ContentLe ngth;
byte[] arrayFile = new byte [fileLen];
Stream strm = this.TextBoxFil eToUpload.Poste dFile.InputStre am;
string contentType = this.TextBoxFil eToUpload.Poste dFile.ContentTy pe;
strm.Read(array File, 0, fileLen);

// Run insert commands...

Here is download code fragment:

// Get data into a reader...

// write to browser
Response.Conten tType = reader["ContentTyp e"].ToString();
Response.Append Header("Content-Disposition", "attachment ; filename = " +
fileName);
Response.Binary Write((byte[]) reader["FileConten ts"]);

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
15665
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 data
2
2923
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 some file types, I get the following error messsage: IE can not download <file> from <server>. IE was not able to open this internet site. The requested site is either unavalable or can not be found. Can anyone tell me how to save a file of any type?...
8
2984
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) Response.ContentType = "application/x-unknown" ' arbitrary fn = "wallpaper_1_1.jpg" Response.write "<br>" & Server.MapPath("wallpaper") & "<br>" FPath = Server.MapPath("wallpaper") & fn
5
5275
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 files server folder. I am able to upload the files into the fileserver, but while downloading the same i am getting error "file doesn't exist" and the path it shows is localhost temporary internet files.
0
468
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 page. I can get that part to work successfully for me, but this is the part does not work the way I want it to work. After the user has entered in their registration information the download for the file begins, once the download is done I want...
1
4596
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 using
3
1623
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 character) output stream from the response and write the bit image of the pdf file to it. -- thanks - dave
17
9464
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 redirect: Response.Redirect("/website/pdffiles/myreport.pdf"); Response.End; IE opens a "File Download" box and if you click the "open" button then
4
4244
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 this issue when i store and retrieve files of type .doc i am storing the file in a column of datatype image. Here is the code where i insert the file into database. Am sure the code is working. its just not working for .docx protected void...
0
8598
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9152
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9016
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8887
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6515
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5858
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4613
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2321
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.