downloading zip file using webResponse

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi ,
I am trying to download a zip file from a http site using webResponse .
here's the code
WebRequest wReq ;
wReq = WebRequest.Create(wUri ) ;
wReq.Credentials = new NetworkCredential (_uid,_psswd);
wReq.Timeout = 6000000;
WebResponse wRes = wReq.GetResponse();
Stream wOutput = wRes.GetResponseStream();
BinaryReader br = new BinaryReader (wOutput);
FileStream fs = new FileStream (_saveLocation + _filename,FileMode.Create );
BinaryWriter writer = new BinaryWriter (fs );
byte bWr ;

while(true)
{
try
{
bWr = br.ReadByte();
writer.Write(bWr);
}
catch(EndOfStreamException ex)
{
break;
}
}

This works fine to download file for 2 - 3 MB but when it comes to
download 5 - 6 MB files it encountres endOFstreamexception at around 2 - 3 MB
and doesn't download the complete file .
can any one help me to rectify this problem .
Thanks and Regards,
Rajiv
 
Have you tried downloading the file from a local webserver?

Gabriel Lozano-Morán
 
Back
Top