ASP.Net : Force File Download

‘ 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
Response.Clear()
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 & “”””)
Response.WriteFile(sPath)
Response.Flush()
Else
Page.RegisterStartupScript(“notfound”, “[javascript function]”)
End If

End Sub

2 thoughts on “ASP.Net : Force File Download

  • September 13, 2006 at 12:32 am
    Permalink

    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.

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: