Click here to Skip to main content
15,880,725 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I'm a newbie in developing a simple program using ASP.net. I want to view a PDF file that is stored in (1) local machine and (2) web server. Several suggestions and answers were listed in programming sites, but I can't seem to apply it in my program. Please help me. Thanks in advance.
Posted
Updated 26-Apr-15 23:01pm
v2
Comments
Leo Chapiro 27-Apr-15 5:28am    
What have you tried?
Member 11644848 27-Apr-15 21:56pm    
I tried this one. But I can't seem to work it out.



Imports System.Net

Partial Class VBCodetoShowPDF
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs)

End Sub
Protected Sub btnpdf_Click(sender As Object, e As EventArgs)
Dim path As String = Server.MapPath("sample.pdf")
Dim client As New WebClient()
Dim buffer As Byte = client.DownloadData(path)

If buffer IsNot Nothing Then
Response.ContentType = "application/pdf"
Response.AddHeader("content-length", buffer.Length.ToString())
Response.BinaryWrite(buffer)
End If
End Sub
End Class
[no name] 27-Apr-15 5:31am    
Use itextsharp.
Member 11644848 27-Apr-15 21:55pm    
hi,
I haven't tried it yet. But I want it a simple code. I'm newbie in ASP.net. :D

1 solution

If a user has PDF reader installed in his machine, he can directly view your pdf link. For ex - http://www.cheat-sheets.org/saved-copy/aspnet-life-cycles-events.pdf[^]
You will be able to open this of you have pdf reader installed. If you need a custom viewer which should work even without client having PDF reader installed, you will have to write code to implement one. There are already lot of examples on web how to implement it - Google search - Show PDF file asp.net[^]. Not sure how you couldn't find anything.
 
Share this answer
 
v2
Comments
Member 11644848 27-Apr-15 21:30pm    
Hi ankur,

I've searched in Google but some of it has C# codes. I'm not yet familiar with C#. Below is the code that I'm trying to apply but I can't seem to get it. I want to view the PDF in my localhost and web server. Please help. Thanks. (newbie)

===========================================================

Imports System.Net

Partial Class VBCodetoShowPDF
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs)

End Sub
Protected Sub btnpdf_Click(sender As Object, e As EventArgs)
Dim path As String = Server.MapPath("sample.pdf")
Dim client As New WebClient()
Dim buffer As Byte = client.DownloadData(path)

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

===========================================================
Ankur\m/ 30-Apr-15 6:18am    
The are lot of converters available online. http://www.developerfusion.com/tools/convert/csharp-to-vb/ this is the one I have used a lot in the past. It's an online tool and will change the code for you in seconds. This one's from Telerik - http://converter.telerik.com/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900