IncomingFile Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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 |
| ContentUrl |
Browsable URL to the file in OneDrive/SharePoint, as sent on the attachment's |
| Extension |
File extension without the dot (e.g. |
| 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 ( |
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. |