what I learn is what u c

ASP.Net : Force File Download

with 3 comments

‘ Stream File Content to Browser

Sub Download(ByVal sPath As String, ByVal iFormCode As Integer, ByVal sExt As String)

Dim sFileName As String
sFileName = CType(iFormCode, String) & “.” & sExt
‘Dim filename As String = sPath
If sExt.ToLower = “pdf” Then
Response.ContentType = “application/pdf”
ElseIf sExt.ToLower = “doc” Then
Response.ContentType = “application/doc”
End If
If File.Exists(sPath) Then
Response.AddHeader(“Content-Disposition”, “attachment; filename=””” & sFileName & “”””)
Page.RegisterStartupScript(“notfound”, “[javascript function]”)
End If

End Sub


Written by gchandra

February 15, 2006 at 5:32 pm

Posted in Web Coding

3 Responses

Subscribe to comments with RSS.

  1. Pdf Files are downloaded in the system but give error at opening time that file is damaged, other files works good, how to solve theis problem.


    September 13, 2006 at 12:32 am

  2. Anwar :

    Sometimes this happen when acrobat is trying to update itself when opening it. If that is your case try updating it first and try this one.


    There is another (similar to this one) way of doing the same. This i used for csv you can change it to PDF.


    September 13, 2006 at 4:40 pm

  3. here a complete example to download files

    It also explains some interesting security issues.


    April 28, 2011 at 8:41 am

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: