Home All Groups Group Topic Archive Search About

does anyone see what is wrong with my .gif download logic? no matter what image url i try it downloa

Author
19 Feb 2007 6:23 AM
dr
does anyone see what is wrong with my .gif download logic? no matter what
image url i try it downloads a junk file that can't be opened in any paint
program.


System.Net.WebRequest myRequest = System.Net.WebRequest.Create(url);
System.Net.WebResponse myResponse = myRequest.GetResponse();
System.IO.Stream imgStream = myResponse.GetResponseStream();
long len = myResponse.ContentLength;
byte[] binarydata = new byte[len];
System.IO.Stream streambinary = myResponse.GetResponseStream();
streambinary.Read(binarydata, 0, (int)len);
using(System.IO.BinaryWriter binWriter = new
System.IO.BinaryWriter(System.IO.File.Open(@"C:\foo.gif",
System.IO.FileMode.Create)))
{
binWriter.Write(binarydata, 0, (int)len);
}

Author
19 Feb 2007 6:42 AM
Göran_Andersson
dr wrote:
Show quote
> does anyone see what is wrong with my .gif download logic? no matter what
> image url i try it downloads a junk file that can't be opened in any paint
> program.
>
>
> System.Net.WebRequest myRequest = System.Net.WebRequest.Create(url);
> System.Net.WebResponse myResponse = myRequest.GetResponse();
> System.IO.Stream imgStream = myResponse.GetResponseStream();
> long len = myResponse.ContentLength;
> byte[] binarydata = new byte[len];
> System.IO.Stream streambinary = myResponse.GetResponseStream();
> streambinary.Read(binarydata, 0, (int)len);
> using(System.IO.BinaryWriter binWriter = new
> System.IO.BinaryWriter(System.IO.File.Open(@"C:\foo.gif",
> System.IO.FileMode.Create)))
> {
>  binWriter.Write(binarydata, 0, (int)len);
> }
>

I replied to this in the C# group. If you post to several groups, please
to a proper cross posting, so that the replies appear in all groups.

--
Göran Andersson
_____
http://www.guffa.com

AddThis Social Bookmark Button