‘ 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 IfEnd Sub
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.
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.
http://gchandra.wordpress.com/2005/05/03/aspnet-vb-write-to-memory-stream/