C# download big file

I had validated this.To download SSMS which is more than 500M+
 static void Main(string[] args)
        {
            string url = "https://go.microsoft.com/fwlink/?linkid=2108895&clcid=0x409";
            DownloadBigFile(new Uri(url), "ssms.exe");             
        }

        static void DownloadBigFile(Uri url, string outputFilePath)
        {
            const int BUFFER_SIZE = 16 * 1024;
            using (var outputFileStream = File.Create(outputFilePath, BUFFER_SIZE))
            {
                var req = WebRequest.Create(url);
                using (var response = req.GetResponse())
                {
                    using (var responseStream = response.GetResponseStream())
                    {
                        var buffer = new byte[BUFFER_SIZE];
                        int bytesRead;
                        do
                        {
                            bytesRead = responseStream.Read(buffer, 0, BUFFER_SIZE);
                            outputFileStream.Write(buffer, 0, bytesRead);
                        } while (bytesRead > 0);
                    }
                }
            }
        }

 

posted @ 2019-11-10 14:02  FredGrit  阅读(421)  评论(0编辑  收藏  举报