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¶
- Map the virtual path to a physical path with
Server.MapPathand read the whole file into a byte array. - Derive the
Content-Typefrom the four-character file extension: (BR-CORE-027) .txt→text/plain.csv→application/vnd.ms-excel- Any other extension → an empty content type.*
- Write the
content-disposition: attachment; filename=…andContent-LengthHTTP response headers. BinaryWritethe file bytes to the response and callResponse.End().
Process flow¶
The following diagram visualizes this operation's control flow.
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
.txtor.csvreceive an emptyContent-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¶
Sources¶
SAIF.Presentation.Web.Core.Infragistics111/clsMailMessage.vb