473,394 Members | 1,742 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,394 software developers and data experts.

Writing a binary file...

Using the HttpWebRequest I'm downloading a PDF file and am trying to save it
to the hard drive, but it keeps ending up corrupt (according to adobe
acrobat). I know the PDF file isn't corrupt because I can view it if I save
it from IE.

I've tried saving it using the BinaryWriter, TextWriter, and StreamWriter.
All have produced the corrupt file.

Anyone know what the problem is?
Nov 20 '05 #1
4 2179
set ContentType property of your HttpResponse to "application/pdf " (not
100% sure, but something like that)
then just write your binary pdf data with the BinaryWrite method
Dim bytes() As Byte = pdfFileAsByteArray
Response.Buffer = True
Response.ContentType = "application/pdf "
Response.BinaryWrite(bytes)
Response.End()
Dominique
"Greg" <no****@nospam.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Using the HttpWebRequest I'm downloading a PDF file and am trying to save it to the hard drive, but it keeps ending up corrupt (according to adobe
acrobat). I know the PDF file isn't corrupt because I can view it if I save it from IE.

I've tried saving it using the BinaryWriter, TextWriter, and StreamWriter.
All have produced the corrupt file.

Anyone know what the problem is?

Nov 20 '05 #2
Cor
Hi Greg,

I always skip things as "Writing binary file" (Armin has on that better
answers than me) but now I see you are talking about downloading.

Did you look already to the webclient.downloadfile

That is so easy to use.

I hope this helps?

Cor
Nov 20 '05 #3
Greg,
In addition to the other comments, it sounds like you are not reading a
binary file!

Either on your read or your write (or both) you have an System.Text.Encoding
object set, as BinaryWriter, TextWriter, and StreamWriter all have an
Encoding property.

I would simply read the underlying Stream object form the HttpWebRequest for
input & FileStream for output and read & write blocks of raw bytes. Thus
avoiding any potential encoding problems.

In other words I would not use a BinaryWriter, TextWriter, and StreamWriter
nor a BinaryReader, TextReader or a TextWriter.

Hope this helps
Jay

"Greg" <no****@nospam.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Using the HttpWebRequest I'm downloading a PDF file and am trying to save it to the hard drive, but it keeps ending up corrupt (according to adobe
acrobat). I know the PDF file isn't corrupt because I can view it if I save it from IE.

I've tried saving it using the BinaryWriter, TextWriter, and StreamWriter.
All have produced the corrupt file.

Anyone know what the problem is?

Nov 20 '05 #4
"Greg" <no****@nospam.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Using the HttpWebRequest I'm downloading a PDF file and am trying to save it to the hard drive, but it keeps ending up corrupt (according to adobe
acrobat). I know the PDF file isn't corrupt because I can view it if I save it from IE.

I've tried saving it using the BinaryWriter, TextWriter, and StreamWriter.
All have produced the corrupt file.

Anyone know what the problem is?


Thanks for everyones help. I was finally able to write in binary format.
Nov 20 '05 #5

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

Similar topics

4
by: john smith | last post by:
Hi, I have a file format that is going to contain some parts in ascii, and some parts with raw binary data. Should I open this file with ios::bin or no? For example: filename: a.bin number of...
6
by: Sebastian Kemi | last post by:
How should a write a class to a file? Would this example work: object *myobject = 0; tfile.write(reinterpret_cast<char *>(myobject), sizeof(*object)); / sebek
4
by: Simon | last post by:
Hi all, I have a process, where I take a dataset from an SQL call, and need to write an XML file from that dataset. The data set can contain 10's of tables, each with 100's of rows, and I have...
5
by: rob | last post by:
hey every1, I've got alot of data to write out to file and it's all just 1's and 0's. It's all stored in 2 dimensional arrays of width 32 and varying height. At the moment it's all just...
3
by: Romain | last post by:
Hello, I am writing out a binary file. I figured that the number "10" is automaticaly converted to "OD OA" instead of "OD". "OD" and "OA" are line feed and carriage return. I know it does...
6
by: DanielEKFA | last post by:
Hey there :) I was once told that the STL classes had member functions to write their data to disk and to restore that data. Searching google (and why are there no "stl" or "map" manpages?), it...
2
by: Jeevan | last post by:
Hi, I have an array of data (which I am getting from a socket connection). I am working on a program which acts on this data but the program is written to work on data from a file (not from an...
3
by: nicolasg | last post by:
Hi, I'm trying to open a file (any file) in binary mode and save it inside a new text file. After that I want to read the source from the text file and save it back to the disk with its...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
5
by: zehra.mb | last post by:
Hi, I had written application for storing employee data in binary file and reading those data from binary file and display it in C language. But I face some issue with writing data to binary file....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.