WebClient.DownloadFileTaskAsync Method (System.Net) (original) (raw)
Source:
Source:
Source:
Source:
Downloads the specified resource to a local file as an asynchronous operation using a task object.
public:
System::Threading::Tasks::Task ^ DownloadFileTaskAsync(Uri ^ address, System::String ^ fileName);
public System.Threading.Tasks.Task DownloadFileTaskAsync(Uri address, string fileName);
[System.Runtime.InteropServices.ComVisible(false)]
public System.Threading.Tasks.Task DownloadFileTaskAsync(Uri address, string fileName);
member this.DownloadFileTaskAsync : Uri * string -> System.Threading.Tasks.Task
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.DownloadFileTaskAsync : Uri * string -> System.Threading.Tasks.Task
Public Function DownloadFileTaskAsync (address As Uri, fileName As String) As Task
Parameters
address
The URI of the resource to download.
fileName
The name of the file to be placed on the local computer.
Returns
The task object representing the asynchronous operation.
Attributes
Exceptions
The address
parameter is null
.
-or-
The fileName
parameter is null
.
The URI formed by combining BaseAddress and address
is invalid.
-or-
An error occurred while downloading the resource.
The local file specified by fileName
is in use by another thread.
Remarks
Caution
WebRequest
, HttpWebRequest
, ServicePoint
, and WebClient
are obsolete, and you shouldn't use them for new development. Use HttpClient instead.
This operation will not block. The returned Task object will complete after the data resource has been downloaded.
This method downloads the resource at the URI specified by in the address
parameter. When the download completes successfully, the downloaded file is named fileName
on the local computer. The file is downloaded asynchronously using thread resources that are automatically allocated from the thread pool.
In .NET Framework and .NET Core 1.0, you can cancel asynchronous operations that have not completed by calling the CancelAsync method.
If the BaseAddress property is not an empty string ("") and address
does not specify an absolute URI, address
must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. If the QueryString property is not an empty string, it is appended to address
.
This method uses the RETR command to download an FTP resource. For an HTTP resource, the GET method is used.
When using this method in an ASP.NET page, you will receive an error if the account that the page executes under does not have permission to access the local file.