Solved

Response.BinaryWrite not working.

Posted on 2004-09-17
5
427 Views
Last Modified: 2008-03-03
i am trying to output an image using response.binarywrite.
the following is teh code i am using:

Dim objStream
  Set objStream = Server.CreateObject("ADODB.Stream")
 
  'Open a GIF file
  objStream.Type = adTypeBinary
  objStream.Open
  objStream.LoadFromFile "C:\Image.png"
 
  'Output the contents of the stream object
  Response.ContentType = "image/png"
  Response.BinaryWrite objStream.Read
 
  'Clean up....
  objStream.Close
  Set objStream = Nothing

instead of outputting an image, it just outputs a string of byte (i think) data. eg. ‰PNG  IHDRg&™Ôº IDATxœì½\÷ÿO¿µßÚ«í¥={1­ÉÙœ—šži½×r—œ1­Müzš#Õ¼r•Zs¡§gMj¯ä§•‡Õ”$Ö˜„FkÕ« *âWAþ‰ŠBåËÿ™ß볟evvfvvfv—¿ï烇îÎÎοù¼>ïÏçý'D ‚ B!ƒ}A1l Õ$‚ ½0Õ´ÙzbcKð·eK^k¬m·÷ΟŸ[Yi¨#”c±Ôð£µZ¯ä~.b§ë֝Îξ®½f\\iTTö¶m•s`横jÃ¥¦ÖI64ta¡t VÀÎ?Z¶,W€¿ññŸà4qÏ8÷Äõ naM¼

does anyone know what is happening??
0
Comment
Question by:hkdcde
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 15

Expert Comment

by:joeposter649
ID: 12084886
Try Response.ContentType = "application/octet-stream" or Response.ContentType = "image/gif".
0
 
LVL 19

Expert Comment

by:peh803
ID: 12084892
in order to use response.binarywrite, I believe you first need to use the request.binaryread method to retrieve your binary data.

also, do you have the adovbs.inc included?  If not, you'll need to assing a value to your adTypeBinary constant, as they are not inherently available to vbscript applications (forgive me if you already know this)...

peh803
0
 
LVL 19

Accepted Solution

by:
peh803 earned 250 total points
ID: 12084945
adTypeBinary = 1, by the way...

Also, try a Response.Clear right before the call to BinaryWrite.

peh803
0
 

Author Comment

by:hkdcde
ID: 12085066
Response.Clear did it!!!
why did this get it to work?

thanks peh803
0
 
LVL 19

Expert Comment

by:peh803
ID: 12085130
magic.... :)

okay, you don't believe in magic?

the response.binarywrite method is a bit fragile and thus requires gentle treatment... :)

Allowing the script to generate additional textual output (through Response.Write or directly) may corrupt the data sent. For example -- trailing bytes appended to an image streamed binary. It is typically a good idea to use response.end at the end of the script and response.clear at the beginning in order to avoid any output.

anyways, glad to help.

peh803
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
If-Then-Else ASP problem 6 78
ASP AND XML 3 42
Record locking on classic ASP 3 64
Help with IIS intermittent hangs on Windows 2012 5 64
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question