I'm trying to read a PDF into a byte array from a URL using the
HttpWebResponse. The only way I've been able to do it is by using a
BinaryReader off the response stream. This works, but it's really slow, and
because the stream doesn't support peaks, I have jump through some hoops.
Here is how I'm doing it now. It seems to work, but it's really slow. What
is a better way to do this?
Thanks,
Erick
Stream binStream = response.GetResponseStream();
BinaryReader reader = new BinaryReader(binStream);
int len = (int)res.ContentLength;
if (len == 0) {
len = 100000;
}
ArrayList tmp = new ArrayList(len);
try {
while (true) {
tmp.Add(reader.ReadByte());
}
} catch (EndOfStreamException) {
byte b = 0;
_binaryContent = (byte[])tmp.ToArray(b.GetType());
}
reader.Close();
binStream.Close();
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.