There is a quite good example in the documentations on
HttpWebResponse.GetResponseStream()
using that example substitute the code following the line
Stream receiveStream = myHttpWebResponse.GetResponseStream();
with something like this
byte[] data = ReadStream(receiveStream);
FileStream fs = File.Create("myfile.dat");
fs.Write(data, 0, data.Length);
fs.Close();
....
private byte[] ReadStream(Stream receiveStream)
{
byte[] buffer = new byte[4096]; // size of the buffer can be adjusted for
speed optimization
using(MemoryStream ms = new MemoryStream())
{
while(true)
{
int count = receiveStream.Read(buffer, 0, buffer.Length);
if(count <= 0) // no more to read, or possibly no feed
return ms.ToArray();
ms.Write(buffer, 0, read);
// update read status here
// unless you are doing multiple threads with invokes
// you will also want to do an Application.DoEvents()
// or nothing will appear to be updated
label1.Text = ms.Length + " bytes read";
Application.DoEvents();
}
}
PS! this code is untested and may contain typos.
--
Happy Coding!
Morten Wennevik [C# MVP]