Επεξεργασία

Κοινή χρήση μέσω


WebClient.UploadFileAsync Method

Definition

Uploads the specified local file to the specified resource. These methods do not block the calling thread.

Overloads

UploadFileAsync(Uri, String)

Uploads the specified local file to the specified resource, using the POST method. This method does not block the calling thread.

UploadFileAsync(Uri, String, String)

Uploads the specified local file to the specified resource, using the POST method. This method does not block the calling thread.

UploadFileAsync(Uri, String, String, Object)

Uploads the specified local file to the specified resource, using the POST method. This method does not block the calling thread.

UploadFileAsync(Uri, String)

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

Uploads the specified local file to the specified resource, using the POST method. This method does not block the calling thread.

public:
 void UploadFileAsync(Uri ^ address, System::String ^ fileName);
public void UploadFileAsync (Uri address, string fileName);
member this.UploadFileAsync : Uri * string -> unit
Public Sub UploadFileAsync (address As Uri, fileName As String)

Parameters

address
Uri

The URI of the resource to receive the file. For HTTP resources, this URI must identify a resource that can accept a request sent with the POST method, such as a script or ASP page.

fileName
String

The file to send to the resource.

Exceptions

The address parameter is null.

-or-

The fileName parameter is null.

The URI formed by combining BaseAddress and address is invalid.

-or-

fileName is null, is Empty, contains invalid character, or the specified path to the file does not exist.

-or-

An error occurred while opening the stream.

-or-

There was no response from the server hosting the resource.

-or-

The Content-type header begins with multipart.

Remarks

Caution

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete, and you shouldn't use them for new development. Use HttpClient instead.

The file is sent asynchronously using thread resources that are automatically allocated from the thread pool. To receive notification when the file upload completes, add an event handler to the UploadFileCompleted event.

This method does not block the calling thread while the file is being sent. To send a file and block while waiting for the server's response, use one of the UploadFile methods.

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 (""), 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 STOR command to upload an FTP resource. For an HTTP resource, the POST 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.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by UploadFile(Uri, String).

Applies to

UploadFileAsync(Uri, String, String)

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

Uploads the specified local file to the specified resource, using the POST method. This method does not block the calling thread.

public:
 void UploadFileAsync(Uri ^ address, System::String ^ method, System::String ^ fileName);
public void UploadFileAsync (Uri address, string? method, string fileName);
public void UploadFileAsync (Uri address, string method, string fileName);
member this.UploadFileAsync : Uri * string * string -> unit
Public Sub UploadFileAsync (address As Uri, method As String, fileName As String)

Parameters

address
Uri

The URI of the resource to receive the file. For HTTP resources, this URI must identify a resource that can accept a request sent with the POST method, such as a script or ASP page.

method
String

The method used to send the data to the resource. If null, the default is POST for http and STOR for ftp.

fileName
String

The file to send to the resource.

Exceptions

The address parameter is null.

-or-

The fileName parameter is null.

The URI formed by combining BaseAddress and address is invalid.

-or-

fileName is null, is Empty, contains invalid character, or the specified path to the file does not exist.

-or-

An error occurred while opening the stream.

-or-

There was no response from the server hosting the resource.

-or-

The Content-type header begins with multipart.

Remarks

Caution

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete, and you shouldn't use them for new development. Use HttpClient instead.

The file is sent asynchronously using thread resources that are automatically allocated from the thread pool. To receive notification when the file upload completes, add an event handler to the UploadFileCompleted event.

This method does not block the calling thread while the file is being sent. To send a file and block while waiting for the server's response, use one of the UploadFile methods.

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 (""), 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 STOR command to upload an FTP resource. For an HTTP resource, the POST 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.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by UploadFile(Uri, String, String).

Applies to

UploadFileAsync(Uri, String, String, Object)

Source:
WebClient.cs
Source:
WebClient.cs
Source:
WebClient.cs

Uploads the specified local file to the specified resource, using the POST method. This method does not block the calling thread.

public:
 void UploadFileAsync(Uri ^ address, System::String ^ method, System::String ^ fileName, System::Object ^ userToken);
public void UploadFileAsync (Uri address, string? method, string fileName, object? userToken);
public void UploadFileAsync (Uri address, string method, string fileName, object userToken);
member this.UploadFileAsync : Uri * string * string * obj -> unit
Public Sub UploadFileAsync (address As Uri, method As String, fileName As String, userToken As Object)

Parameters

address
Uri

The URI of the resource to receive the file. For HTTP resources, this URI must identify a resource that can accept a request sent with the POST method, such as a script or ASP page.

method
String

The method used to send the data to the resource. If null, the default is POST for http and STOR for ftp.

fileName
String

The file to send to the resource.

userToken
Object

A user-defined object that is passed to the method invoked when the asynchronous operation completes.

Exceptions

The address parameter is null.

-or-

The fileName parameter is null.

The URI formed by combining BaseAddress and address is invalid.

-or-

fileName is null, is Empty, contains invalid character, or the specified path to the file does not exist.

-or-

An error occurred while opening the stream.

-or-

There was no response from the server hosting the resource.

-or-

The Content-type header begins with multipart.

Remarks

Caution

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete, and you shouldn't use them for new development. Use HttpClient instead.

The file is sent asynchronously using thread resources that are automatically allocated from the thread pool. To receive notification when the file upload completes, add an event handler to the UploadFileCompleted event.

This method does not block the calling thread while the file is being sent. To send a file and block while waiting for the server's response, use one of the UploadFile methods.

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 (""), 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 STOR command to upload an FTP resource. For an HTTP resource, the POST 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.

Applies to