P
Pete Davis
I'm trying to read some image files off of our web site and the code isn't
working. The files appear to be corrupt. The file size is correct the image
becomes corrupt after maybe 20 or 30 lines.
The url might be something like:
http://www.website.com/folder/chart1.jpg
And I want to save this into a file called chart1.jpg in a folder I've
specified. The code is:
WebRequest req = WebRequest.Create(url);
using (WebResponse resp = req.GetResponse())
{
using(Stream stream = resp.GetResponseStream())
{
string outFile = _destinationTextBox.Text + @"\" + filename;
FileStream fs = new FileStream(outFile, FileMode.Create);
byte[] buffer = new byte[resp.ContentLength];
stream.Read(buffer, 0, (int) resp.ContentLength);
fs.Write(buffer, 0, (int) resp.ContentLength);
fs.Close();
}
}
What am I missing or where is the bug I'm overlooking?
Thanks.
Pete
working. The files appear to be corrupt. The file size is correct the image
becomes corrupt after maybe 20 or 30 lines.
The url might be something like:
http://www.website.com/folder/chart1.jpg
And I want to save this into a file called chart1.jpg in a folder I've
specified. The code is:
WebRequest req = WebRequest.Create(url);
using (WebResponse resp = req.GetResponse())
{
using(Stream stream = resp.GetResponseStream())
{
string outFile = _destinationTextBox.Text + @"\" + filename;
FileStream fs = new FileStream(outFile, FileMode.Create);
byte[] buffer = new byte[resp.ContentLength];
stream.Read(buffer, 0, (int) resp.ContentLength);
fs.Write(buffer, 0, (int) resp.ContentLength);
fs.Close();
}
}
What am I missing or where is the bug I'm overlooking?
Thanks.
Pete