public DownloadFile ( System address, string fileName ) : void | ||
address | System | |
fileName | string | |
return | void |
using System.Net; string url = "https://example.com/file.pdf"; string filePath = @"C:\Downloads\file.pdf"; WebClient client = new WebClient(); client.DownloadFile(url, filePath);
using System.Net; using System.Threading.Tasks; string url = "https://example.com/file.pdf"; string filePath = @"C:\Downloads\file.pdf"; WebClient client = new WebClient(); // Download the file asynchronously Task downloadTask = client.DownloadFileTaskAsync(new Uri(url), filePath); // Do other work while the file is downloading DoOtherWork(); // Wait for the download to complete downloadTask.Wait();This code downloads a file from the specified URL asynchronously, allowing the application to do other work while the file is downloading. The DownloadFileTaskAsync method returns a Task object that can be waited on to know when the download is complete. This method belongs to the System.Net.WebClient class which is a part of the .NET Framework library.
public DownloadFile ( System address, string fileName ) : void | ||
address | System | |
fileName | string | |
return | void |