---
title: Stream a file download to the browser
summary: Reads an already-created file and streams it to the browser as an HTTP attachment download.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-08-17
library: SAIF.Presentation.Web.Core.Infragistics111
reference_type: package
operation_id: OP-CORE-009
trigger: Consuming page requests a download of an already-created file
---

# Stream a file download to the browser

This operation reads a file from the web server's file system and streams it back to the browser as an HTTP attachment, selecting the `Content-Type` header from the file's extension.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-CORE-009 |
| **Trigger** | Consuming page requests a download of an already-created file |
| **Inputs** | Virtual file name, owning `AppViewPageBase` |
| **Outputs** | HTTP response carrying the file as an attachment |
| **Primary components** | `Utilities.clsMailMessage.StreamDownloadFile` |
| **Entry point** | `SAIF.Presentation.Web.Core.Infragistics111/clsMailMessage.vb` |

## Steps

1. Map the virtual path to a physical path with `Server.MapPath` and read the whole file into a byte array.
2. Derive the `Content-Type` from the four-character file extension: ([BR-CORE-027](../business-rules.md#br-core-027-download-content-type-is-derived-from-the-file-extension-txt-textplain-csv-applicationvndms-excel))
   - `.txt` → `text/plain`
   - `.csv` → `application/vnd.ms-excel`
   - Any other extension → an empty content type.*
3. Write the `content-disposition: attachment; filename=…` and `Content-Length` HTTP response headers.
4. `BinaryWrite` the file bytes to the response and call `Response.End()`.

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start([StreamDownloadFile called]) --> S1[Server.MapPath virtual to physical path]
	S1 --> S2[Read whole file into byte array]
	S2 --> S3{File extension?}
	S3 -->|.txt| S4[Content-Type: text/plain]
	S3 -->|.csv| S5[Content-Type: application/vnd.ms-excel]
	S3 -->|Other| S6[Content-Type: empty]
	S4 --> S7[Write content-disposition and Content-Length headers]
	S5 --> S7
	S6 --> S7
	S7 --> S8[BinaryWrite bytes]
	S8 --> S9[Response.End]
```

## Failure and edge-case behavior
- File extensions other than `.txt` or `.csv` receive an empty `Content-Type`, which browsers may handle inconsistently.*
- No existence check is documented before `Server.MapPath`/file read; a missing file would surface as a runtime I/O exception to the caller.**

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

## Sources
- `SAIF.Presentation.Web.Core.Infragistics111/clsMailMessage.vb`
