What is a simple way of downloading a file from a URL path?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
You may need to know the status and update a ProgressBar during the file download or use credentials before making the request.
Here it is, an example that covers these options. Lambda notation and String interpolation has been used:
Also you can use DownloadFileAsync method in WebClient class. It downloads to a local file the resource with the specified URI. Also this method does not block the calling thread.
Sample:
For more information:
http://csharpexamples.com/download-files-synchronous-asynchronous-url-c/
Complete class to download a file while printing status to console.
Usage:
Check for a network connection using
GetIsNetworkAvailable()
to avoid creating empty files when not connected to a network.