Method CreateFromStreamAsync
CreateFromStreamAsync(Stream, string, CancellationToken)
Creates a new Attachment instance that references the provided stream directly, without copying its content into managed memory.
public static Task<Attachment> CreateFromStreamAsync(Stream data, string name, CancellationToken cancellationToken = default)
Parameters
dataStreamA readable, seekable Stream containing the attachment data. The stream is referenced directly — no copy is made. The caller retains ownership: the stream is not disposed by this instance, and it must remain open and valid for the lifetime of the Attachment.
namestringThe logical file name associated with this attachment.
cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
- Task<Attachment>
A task that represents the asynchronous operation. The task result contains the created Attachment.
Exceptions
- ArgumentNullException
Thrown when
dataornameisnull.- ArgumentException
Thrown when
datais not readable or not seekable.- UnsupportedFileTypeException
Thrown if the stream data is not one of the supported formats.
- OperationCanceledException
Thrown when the operation is canceled.
- See Also