By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,294 Members | 2,517 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,294 IT Pros & Developers. It's quick & easy.

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.

P: n/a
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:\fo o.gif",
System.IO.FileMode.Create)))
{
binWriter.Write(binarydata, 0, (int)len);
}


Feb 19 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
dr

Did you know that there is a
Webclient.downloadfile

http://msdn2.microsoft.com/en-us/lib...nloadfile.aspx

And very fast.

Much easier,

Cor

"dr" <so*******************@yahoo.comschreef in bericht
news:e%******************@TK2MSFTNGP06.phx.gbl...
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:\fo o.gif",
System.IO.FileMode.Create)))
{
binWriter.Write(binarydata, 0, (int)len);
}




Feb 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.