Hi,
I have a problem downloading a file .
after i connect to the website and get the stream , i treing to write
the file on the HD.
public void SaveStreamToFile(string filePath, Stream stream)
{
// If not all data was provided return false;
//if (string.IsNullOrEmpty(filePath) || stream == null)
// return false;
// System.IO.Stream gzStream = stream; //= new
System.IO.Stream()//(stream,
System.IO.Compression.CompressionMode.Decompress);
FileStream fs = null;
try
{
byte[] inBuffer = new byte[10000];
int bytesRead = 0;
fs = File.Open(filePath, FileMode.Create,
FileAccess.Write, FileShare.Read);
while ((bytesRead = stream.Read(inBuffer, 0,
inBuffer.Length)) > 0)
{
fs.Write(inBuffer, 0, bytesRead);
}
fs.Flush();
// return true;
}
catch (Exception ex)
{
throw ex;
// ExceptionPolicy.HandleException(ex, "Global
Policy");
//return false;
}
finally
{
fs.Close();
}
}
webRequest1.KeepAlive = true;
webRequest1.CookieContainer = cookies;
webRequest1.Accept =
"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
webRequest1.Headers.Set("Accept-Language",
"en-us,en;q=0.5");
webRequest1.Headers.Set("Accept-Encoding", "gzip,deflate");
webRequest1.Headers.Set("Accept-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7");
webRequest1.Headers.Set("Keep-Alive", "300");
WebResponse myResponse1 = webRequest1.GetResponse();
Stream ReceiveStream1 = myResponse1.GetResponseStream();
SaveStreamToFile(@"C:\file.csv", ReceiveStream1);

the problem is that if i want to download a file (as big as 3Mb) it
takes me 40min to do it .
(my internet connection is fast)

please suggest me , how to solve this problem .
Thanks , Rony

Re: Slow Downloading by Otis

Otis
Fri Aug 18 21:56:01 CDT 2006

On 17 Aug 2006 07:33:14 -0700, "rony_16" <rony.vainblat@gmail.com> wrote:

<snip>
>the problem is that if i want to download a file (as big as 3Mb) it
>takes me 40min to do it .
>(my internet connection is fast)
>
>please suggest me , how to solve this problem .
>Thanks , Rony

But is the server and connection at the web site fast? I've seen even small
files take forever to download from slow sites.

I think I also see that you are decompressing the file as you read. That will
add time to the file download.
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com