Skip to content

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:
  4. .txt → text/plain
  5. .csv → application/vnd.ms-excel
  6. Any other extension: sContentType remains an empty string.
  7. Sets Content-Type, content-disposition: attachment; filename=<Filename> (with <Filename> substituted for the actual downloaded file name), and Content-Length response headers.
  8. Writes the bytes with BinaryWrite, then calls Response.End().

Process flow

The following diagram visualizes this operation's control flow.

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.

Sources

  • SAIF.Presentation.Web.Core.Infragistics103\clsMailMessage.vb