欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C# download big file

程序员文章站 2022-06-05 18:58:05
static void Main(string[] args) { string url = "https://go.microsoft.com/fwlink/?linkid=2108895&clcid=0x409"; DownloadBigFile(new Uri(url), "ssms.... ......

 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);
                    }
                }
            }
        }

 

static void main(string[] args)
        {
            string url = "https://go.microsoft.com/fwlink/?linkid=866662";
            downloadbigfile(new uri(url), "sqlserver20192.exe");
            console.readline();
        }

        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);
                    }
                }
            }