How to download a file from the Internet in a WinForm application

I am writing a C # program that I need to download and save a file from a URL.

I have some code that works to get the url from a web service call, however it is hard for me to find a simple example of how to start the download and save the data to a file on disk.

Does anyone have a good example of this or can provide me an example?

Thank!

EDIT - I should mention that these files will be between 3 and 4 GB in size. Therefore, if there are special considerations for files of this size, I would appreciate any advice.

+3
source share
3 answers

WebClient.DownloadData, . , WebRequest.GetResponseStream , WebRequest .

3-4 , , .Net framework. WebClient , []. , VAS ( ) 4 ,.Net - , 2Gb ( x64). , GetResponseStream().

-, HTTP , HTTP/1.1 3.12. Content-Range, . , , , , prpoer accept-ranges, .

, 4Gb - - .

+4

, .

No matter what method you learn to get something from http (WebClient, TcpStream, ...), you should probably be aware of recovery from the very beginning. This should be focused here.

To do this, it would be necessary to check whether Stream of supports GetResponseStream() Seek().

+1
source

Source: https://habr.com/ru/post/1769637/


All Articles