Site menu:

Links:

RSS .NET RSS

RSS Engadget

Site search

Categories

September 2010
M T W T F S S
« Aug    
 12345
6789101112
13141516171819
20212223242526
27282930  

Tags

Blogroll

Provide Link to a file without showing the actual path in asp.net

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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

Write a comment