Saturday, January 30, 2010

Open PDF file in Asp.net using Vb.net on button click event

This example used the asp.net with vb.net coding.

Here i am upload the PDF file path which is already stored on server side hard drive and this file path store in string variable sPath and now i was click the one button from Asp.net page then the particular PDF is open.

Code is below:
Placed following code  in button click event....

Dim client As New System.Net.WebClient()
Dim buffer As [Byte]() = client.DownloadData(sPath)

If buffer IsNot Nothing Then
Response.ContentType = "application/pdf"
Response.AddHeader("content-length", buffer.Length.ToString())
Response.BinaryWrite(buffer)
End If

No comments:

Post a Comment