Upraviť

Zdieľať cez


Socket.SendFileAsync Method

Definition

Overloads

SendFileAsync(String, CancellationToken)

Sends the file fileName to a connected Socket object.

SendFileAsync(String, ReadOnlyMemory<Byte>, ReadOnlyMemory<Byte>, TransmitFileOptions, CancellationToken)

Sends the file fileName and buffers of data to a connected Socket object using the specified TransmitFileOptions value.

SendFileAsync(String, CancellationToken)

Source:
Socket.Tasks.cs
Source:
Socket.Tasks.cs
Source:
Socket.Tasks.cs

Sends the file fileName to a connected Socket object.

public System.Threading.Tasks.ValueTask SendFileAsync (string? fileName, System.Threading.CancellationToken cancellationToken = default);
member this.SendFileAsync : string * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask
Public Function SendFileAsync (fileName As String, Optional cancellationToken As CancellationToken = Nothing) As ValueTask

Parameters

fileName
String

A String that contains the path and name of the file to be sent. This parameter can be null.

cancellationToken
CancellationToken

A cancellation token that can be used to cancel the asynchronous operation.

Returns

A value task that represents the asynchronous send file operation.

Exceptions

The Socket object has been closed.

The Socket object is not connected to a remote host.

The file fileName was not found.

An error occurred when attempting to access the socket.

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

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 SendFile(String).

Applies to

SendFileAsync(String, ReadOnlyMemory<Byte>, ReadOnlyMemory<Byte>, TransmitFileOptions, CancellationToken)

Source:
Socket.Tasks.cs
Source:
Socket.Tasks.cs
Source:
Socket.Tasks.cs

Sends the file fileName and buffers of data to a connected Socket object using the specified TransmitFileOptions value.

public System.Threading.Tasks.ValueTask SendFileAsync (string? fileName, ReadOnlyMemory<byte> preBuffer, ReadOnlyMemory<byte> postBuffer, System.Net.Sockets.TransmitFileOptions flags, System.Threading.CancellationToken cancellationToken = default);
member this.SendFileAsync : string * ReadOnlyMemory<byte> * ReadOnlyMemory<byte> * System.Net.Sockets.TransmitFileOptions * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask
Public Function SendFileAsync (fileName As String, preBuffer As ReadOnlyMemory(Of Byte), postBuffer As ReadOnlyMemory(Of Byte), flags As TransmitFileOptions, Optional cancellationToken As CancellationToken = Nothing) As ValueTask

Parameters

fileName
String

A String that contains the path and name of the file to be sent. This parameter can be null.

preBuffer
ReadOnlyMemory<Byte>

A Byte array that contains data to be sent before the file is sent. This parameter can be null.

postBuffer
ReadOnlyMemory<Byte>

A Byte array that contains data to be sent after the file is sent. This parameter can be null.

flags
TransmitFileOptions

One or more of TransmitFileOptions values.

cancellationToken
CancellationToken

A cancellation token that can be used to cancel the asynchronous operation.

Returns

A value task that represents the asynchronous send file operation.

Exceptions

The Socket object has been closed.

The Socket object is not connected to a remote host.

The file fileName was not found.

An error occurred when attempting to access the socket.

The cancellation token was canceled. This exception is stored into the returned task.

Applies to