Skip to content

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)
  3. .txt → text/plain
  4. .csv → application/vnd.ms-excel
  5. Any other extension → an empty content type.*
  6. Write the content-disposition: attachment; filename=… and Content-Length HTTP response headers.
  7. BinaryWrite the file bytes to the response and call Response.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 .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.**

Sources

  • SAIF.Presentation.Web.Core.Infragistics111/clsMailMessage.vb