P
Praveen
Hi all,
I have written a class to download pages and files from the internet. The
code is like below
if (WebResp.StatusCode != HttpStatusCode.OK)
{ // throw error }
Stream Strm = WebResp.GetResponseStream();
int n = Strm.Read(b,0,b.Length);
while(n > 0)
{
FS.Write(b,0,n);
n = Strm.Read(b,0,b.Length);
}
WebResp is the webresponse object from which I get to the download stream. I
am not using the content length to find the file size and do the loop for
that length because http response may not always give the content length.
This works perfectly well except a case if the internet connection breaks
while the code is in the while loop. In this case the Strm.read returns -1
insted of throwing and error that the stream is broken. What happens is the
file is partially downloaded and no error thrown so the application believes
the file download is complete.
Can you suggest some ways of throwing an error if the connection has broken.
Thanks in advance,
Praveen.
I have written a class to download pages and files from the internet. The
code is like below
if (WebResp.StatusCode != HttpStatusCode.OK)
{ // throw error }
Stream Strm = WebResp.GetResponseStream();
int n = Strm.Read(b,0,b.Length);
while(n > 0)
{
FS.Write(b,0,n);
n = Strm.Read(b,0,b.Length);
}
WebResp is the webresponse object from which I get to the download stream. I
am not using the content length to find the file size and do the loop for
that length because http response may not always give the content length.
This works perfectly well except a case if the internet connection breaks
while the code is in the while loop. In this case the Strm.read returns -1
insted of throwing and error that the stream is broken. What happens is the
file is partially downloaded and no error thrown so the application believes
the file download is complete.
Can you suggest some ways of throwing an error if the connection has broken.
Thanks in advance,
Praveen.