Language

IncomingFile Class

Definition

A lazy handle to a file attached to the current inbound activity.

Nothing is downloaded until a byte method is called. The handle stays live and holds no memoized bytes, so each of StreamAsync(CancellationToken)/DownloadAsync(CancellationToken)/TextAsync(Encoding, CancellationToken)/SaveAsAsync(String, CancellationToken) fetches afresh. For a personal file that re-fetch is bounded by the short-lived download URL lifetime and may hit its expiry; to read the same file several ways, call DownloadAsync(CancellationToken) once and reuse the returned DownloadedFile.

public sealed class IncomingFile
type IncomingFile = class
Public NotInheritable Class IncomingFile
Inheritance
IncomingFile

Properties

Name Description
ContentType

The file's MIME type when the source provides one. Always null for BotActivity files: a file.download.info attachment carries no MIME type, only the fileType extension surfaced as Extension. Populated for sources that do carry one, such as a Graph drive item. To learn the type of the bytes you actually received, read ContentType, which is resolved from the download response.

ContentUrl

Browsable URL to the file in OneDrive/SharePoint, as sent on the attachment's contentUrl. Not fetchable for bytes despite the name, but it is the locator a Graph /shares resolution keys off; bytes come from DownloadAsync(CancellationToken) or StreamAsync(CancellationToken).

Extension

File extension without the dot (e.g. pdf), taken from the platform-supplied fileType. Absent when the wire omits it.

Name

Display name including extension when known.

Raw

The raw underlying attachment/graph object for escape-hatch access.

Scope

Conversation scope the file arrived in (the SDK's ConversationType).

Source

Where the SDK found the file. Only BotActivity is produced today.

UniqueId

The ODSP/OneDrive identifier for the file when the platform reports it (content.uniqueId). Useful for correlation, dedup and logging, but not for retrieval: the Graph fetch resolves bytes from ContentUrl through /shares, and this value arrives as a GUID, which is a SharePoint listItemUniqueId shape rather than a Graph driveItem.id. Present only when the wire provided it.

Methods

Name Description
DownloadAsync(CancellationToken)

Fetch the whole file and buffer it into a DownloadedFile snapshot you own. Lazy and not memoized: calling again re-fetches. If you already hold a DownloadedFile, call its SaveAsAsync(String, CancellationToken) rather than this handle's, which would re-fetch.

SaveAsAsync(String, CancellationToken)

Stream the bytes straight to a local file path, so saving a large file never materializes it in memory.

StreamAsync(CancellationToken)

Stream the bytes. Low-level primitive: returns the response body stream directly, single-consumption, not buffered or retained. Use for large files and pipelines (parse-as-you-go, pipe to disk). DownloadAsync(CancellationToken) is built on this. Uncapped: the consumer bounds it by how much it reads. Dispose the returned stream to release the underlying connection.

TextAsync(Encoding, CancellationToken)

Convenience: run DownloadAsync(CancellationToken) then decode the bytes as UTF-8 (or a provided encoding). Re-fetches on each call (no memoized bytes); to read bytes several ways hold one DownloadedFile instead. No content-type check; decoding is lossy (invalid bytes become U+FFFD and never throw). For strict or binary-safe reads, use the Bytes of a DownloadAsync(CancellationToken) result.

Applies to