Method CreateFromUriAsync
CreateFromUriAsync(Uri, AttachmentDownloadingProgressCallback, CancellationToken)
Creates a new Attachment instance asynchronously by loading content from the specified URI.
public static Task<Attachment> CreateFromUriAsync(Uri uri, Attachment.AttachmentDownloadingProgressCallback downloadingProgress = null, CancellationToken cancellationToken = default)
Parameters
uriUriThe URI to load the attachment from. Supports
file://for local files andhttp://orhttps://for remote resources.downloadingProgressAttachment.AttachmentDownloadingProgressCallbackAn optional callback to report download progress for remote URIs. The callback receives the total content length (if known) and bytes read so far. Return
falseto cancel the download.cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
- Task<Attachment>
A task that represents the asynchronous operation. The task result contains the loaded Attachment.
Exceptions
- ArgumentNullException
Thrown when
uriisnull.- FileNotFoundException
Thrown when a local file URI points to a non-existent file.
- UnsupportedFileTypeException
Thrown when the downloaded content is not a supported format.
- HttpRequestException
Thrown when the remote resource cannot be downloaded.
- OperationCanceledException
Thrown when the operation is canceled.
- See Also