|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Slow DownloadingI 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 |
|||||||||||||||||||||||