Wednesday 10 October 2007

open pdf in webform

convert the file in byte array(i.e byte()) using function :

'get data from file and return as byte array
Public Function GetFileData(path as string) As Byte()
Try
Dim fsReader As New IO.FileStream(path , IO.FileMode.Open)
Dim data() As Byte = New Byte(fsReader.Length) {}
fsReader.Read(data, 0, fsReader.Length)
fsReader.Close()
Return data
Catch
Throw
End Try
End Function

dim buf() as byte
buf=GetFileData()

If buf.Length > 0 Then
'flush retrieved document
Response.Clear()
Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "Application/pdf"
Response.AddHeader("content-disposition", "inline; filename=ehips_SW_" & sTaskRef & ".pdf")
Response.AddHeader("content-transfer-encoding", "binary")
Response.BinaryWrite(buf)
Response.End()
End If



should display PDF in browser

No comments: