Let’s say you have some file that allow people to download it but you don’t want to expose the actual path for security reason.

Here is the way of doing it, You need to read the file and put that on byte variable then you start omitting slowly instead of the whole chunk. In the next article you will see the error if you omit a big file at once

Public Sub DishUpCFile(ByVal filename As String)

            Dim nBytesRead As Integer = 0
            Const mSize As Integer = 1024
            Dim bytes As Byte() = New Byte(mSize - 1) {}

           'Open or override a file in the local directory
            Dim fsFile As New FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)

            Response.Clear()
            Response.Buffer = True
            Response.ClearHeaders()
            Response.ContentType = "text/csv"
            Response.AddHeader("Content-Disposition", "attachment; filename=AllMembers.csv")

            'Read the first bit of content, then write and read all the content
            'From the FromStream to the ToStream.
            nBytesRead = fsFile.Read(bytes, 0, mSize)

            While nBytesRead > 0
                Response.OutputStream.Write(bytes, 0, nBytesRead)
                nBytesRead = fsFile.Read(bytes, 0, mSize)
            End While

            Response.OutputStream.Close()
            fsFile.Close()
        End Sub