WebClient.DownloadFileTaskAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Downloads the specified resource to a local file as an asynchronous operation using a task object. These methods do not block the calling thread.
Overloads
DownloadFileTaskAsync(String, String) |
Downloads the specified resource to a local file as an asynchronous operation using a task object. |
DownloadFileTaskAsync(Uri, String) |
Downloads the specified resource to a local file as an asynchronous operation using a task object. |
DownloadFileTaskAsync(String, String)
- Source:
- WebClient.cs
- Source:
- WebClient.cs
- Source:
- WebClient.cs
Downloads the specified resource to a local file as an asynchronous operation using a task object.
public:
System::Threading::Tasks::Task ^ DownloadFileTaskAsync(System::String ^ address, System::String ^ fileName);
public System.Threading.Tasks.Task DownloadFileTaskAsync (string address, string fileName);
[System.Runtime.InteropServices.ComVisible(false)]
public System.Threading.Tasks.Task DownloadFileTaskAsync (string address, string fileName);
member this.DownloadFileTaskAsync : string * string -> System.Threading.Tasks.Task
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.DownloadFileTaskAsync : string * string -> System.Threading.Tasks.Task
Public Function DownloadFileTaskAsync (address As String, fileName As String) As Task
Parameters
- address
- String
The URI of the resource to download.
- fileName
- String
The name of the file to be placed on the local computer.
Returns
The task object representing the asynchronous operation.
- Attributes
Exceptions
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.
Note
This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in .NET Framework.
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.
Applies to
DownloadFileTaskAsync(Uri, String)
- Source:
- WebClient.cs
- Source:
- WebClient.cs
- Source:
- WebClient.cs
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
- Uri
The URI of the resource to download.
- fileName
- String
The name of the file to be placed on the local computer.
Returns
The task object representing the asynchronous operation.
- Attributes
Exceptions
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.
Note
This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in .NET Framework.
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.