---
title: Stream a file download
summary: Streams an existing file to the HTTP response as a downloadable attachment.
status: draft
owner: SAIF Documentation Team
last_reviewed: 2026-08-17
library: SAIF.Presentation.Web.Core.Infragistics103
reference_type: package
operation_id: OP-CMM-002
trigger: Explicit call to Utilities.clsMailMessage.StreamDownloadFile
---

# Stream a file download

This operation streams an existing file on disk to the HTTP response as a downloadable attachment, independent of the email-sending functionality in the same class.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-CMM-002 |
| **Trigger** | Call to `Utilities.clsMailMessage.StreamDownloadFile(Filename, inPage)` |
| **Inputs** | Virtual filename, hosting `AppViewPageBase` page |
| **Outputs** | HTTP response written with file bytes; ends the response |
| **Primary components** | `Utilities.clsMailMessage.StreamDownloadFile` |
| **Entry point** | `SAIF.Presentation.Web.Core.Infragistics103\clsMailMessage.vb` |

## Steps

1. Maps the virtual path to a physical path (`inPage.Server.MapPath`), strips the filename to its last path segment.
2. Opens a `FileStream`, reads the full file into a byte array, closes the stream.
3. Derives content type from the last 4 characters of the filename — enforces [BR-CMM-001](../business-rules.md#br-cmm-001-only-txt-and-csv-extensions-receive-an-explicit-content-type):
   - `.txt` → `text/plain`
   - `.csv` → `application/vnd.ms-excel`
   - Any other extension: `sContentType` remains an empty string.
4. Sets `Content-Type`, `content-disposition: attachment; filename=<Filename>` (with `<Filename>` substituted for the actual downloaded file name), and `Content-Length` response headers.
5. Writes the bytes with `BinaryWrite`, then calls `Response.End()`.

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start([StreamDownloadFile called]) --> S1[Map virtual path to physical path]
	S1 --> S2[Read file into byte array]
	S2 --> S3{File extension?}
	S3 -->|.txt| S4a[Content-Type = text/plain]
	S3 -->|.csv| S4b[Content-Type = application/vnd.ms-excel]
	S3 -->|Other| S4c[Content-Type left empty]
	S4a --> S5[Set response headers]
	S4b --> S5
	S4c --> S5
	S5 --> S6[BinaryWrite bytes]
	S6 --> EndOk([Response.End])
```

## Failure and edge-case behavior
- Extensions other than `.txt`/`.csv` are written to the response with no `Content-Type` header value set by this method.
- No exception handling is present around file access; a missing or inaccessible file will surface an unhandled exception.

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

## Sources
- SAIF.Presentation.Web.Core.Infragistics103\clsMailMessage.vb
