473,544 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to open PDF file in ASP.Net

1 New Member
I want to open particular PDF file in my Asp.net application. For that have store the path of PDF file in database. Now I want to open that file on one of the page in my application.
Oct 10 '06 #1
5 56515
mohq82
2 New Member
I want to open particular PDF file in my Asp.net application. For that have store the path of PDF file in database. Now I want to open that file on one of the page in my application.

try the following :

System.Net.WebC lient client = new System.Net.WebC lient();
Byte[] buffer = client.Download Data(path);

if (buffer != null)
{
Response.Conten tType = "applicatio n/pdf";
Response.AddHea der("content-length", buffer.Length.T oString());
Response.Binary Write(buffer);
}

hope it helps.
Nov 26 '06 #2
abbaky
2 New Member
I want to open particular PDF file in my Asp.net application. For that have store the path of PDF file in database. Now I want to open that file on one of the page in my application.

Hi,

If it is ASP .Net just add response.redire ct("The PDF file path") in the code
Nov 27 '06 #3
jammoral
1 New Member
what if I am storing the pdf in a blob column in oracle? how do I assign the binary value to the response function?
Jul 4 '07 #4
firstmalone
1 New Member
I did not see anyone actually answering this question.

I thought if I provide my current solution, I might get some constructive feedback and perhaps some assistance.

While the following ASP.NET 2.0 (2005 SP1) w/ VB.NET 2005 SP1 solution does provide a PDF rendering of the oracle stored blob PDF file, I'd like to display the PDF reader within my current page template - In Classic ASP I would do this by utilizing a report reader object.

How do I do this in ASP.NET 2.0?

If you have a sample from that language would work for me too as I can and do read, understand and develop in C#. (I do not currently have any paying customers who develop in C#, but I do use it.)

[HTML]
<%@ Page Language="vb" AutoEventWireup ="false" CodeBehind="PFD Viewer.aspx.vb" Inherits="Proje ct.PFDViewer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="HTMLHead" runat="server"> <title></title></head><body></body>
</html>
[/HTML]
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.OracleClient
  2.  
  3. Partial Public Class PFDViewer
  4.     Inherits System.Web.UI.Page
  5.  
  6.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  7.         If IsNothing(Session("seUSERGUID")) Then
  8.             Me.Response.Redirect("~\Login.aspx", True)
  9.         Else
  10.             If Not IsPostBack Then
  11.                 Dim Tracker As New clsWebUserTracker(New OracleClient.OracleConnection(ConfigurationManager.ConnectionStrings("AppSecASPNETConnectionString").ConnectionString))
  12.                 Tracker.LogEvent(Request.ServerVariables("Remote_addr").ToString, Me.Page.Request.Url.AbsoluteUri.ToString, Session("seUserName"), Session("seUSERGUID"), Session("seEntityGUID"))
  13.             End If
  14.         End If
  15.         Dim orConn As New OracleConnection(Me.Session("seEntityConnectionString"))
  16.         Dim DM As New clsDocuments(orConn, Nothing)
  17.         If Me.Request("ByType") Then
  18.             DM.getDocumentFileByType(Me.Request("DocCallVal"))
  19.         Else
  20.             DM.getDocumentFileByGUID(Me.Request("DocCallVal"))
  21.         End If
  22.         Me.Title = DM.DocumentTitle & " - " & DM.DocumentType
  23.         If String.IsNullOrEmpty(DM.Filetype) Then
  24.             Response.Write("File Not Available")
  25.         ElseIf Not DM.Filetype.ToUpper = "PDF" Then
  26.             Response.Write("File Not Available")
  27.         Else
  28.             'Write the file directly to the HTTP output stream.
  29.             Dim SR As IO.Stream
  30.             SR = DM.FileBlob
  31.             Dim bw As IO.BinaryReader
  32.             Response.Clear()
  33.             bw = New IO.BinaryReader(SR)
  34.             Dim SendByteArray As Byte()
  35.             SendByteArray = bw.ReadBytes(bw.BaseStream.Length)
  36.             Response.ContentType = "application/pdf"
  37.             Response.AddHeader("Content-Type", "application/pdf")
  38.             Response.AddHeader("Content-Disposition", "inline")
  39.             Response.BinaryWrite(SendByteArray)
  40.             Response.End()
  41.         End If
  42.     End Sub
  43. End Class
  44.  
Mar 7 '08 #5
amity2001
1 New Member
Very very useful...
Thank you very much...

Just translating & refining the code for C# users,

all credit is yours...!


Expand|Select|Wrap|Line Numbers
  1.  
  2.             StreamReader streamReader = new StreamReader(PDFDirectoryPath);
  3.  
  4.             Stream stream = streamReader.BaseStream;
  5.  
  6.             BinaryReader binaryReader = new BinaryReader(stream);
  7.  
  8.             byte[] sendbyteArray = binaryReader.ReadBytes(Convert.ToInt32( binaryReader.BaseStream.Length));
  9.  
  10.             Response.ContentType = "application/pdf";
  11.             Response.AddHeader("Content-Type", "application/pdf");
  12.             Response.AddHeader("Content-Disposition", "inline");
  13.             Response.BinaryWrite(sendbyteArray);
  14.             Response.End();  
  15.  
  16.  
Jan 6 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1616
by: Stephen | last post by:
could someone give me some advise on a problem I have. At present i have a web application which displays pdf files in a web browser using javascript and the window.open method and pointing to a web address like window.open(http://.........). I have been asked to find out if it is possible to do something similar but instead opening a file...
2
5314
by: gary smith | last post by:
I am trying to open a file (file --> open --> file) at an FTP location using visual Studio.net. Unfortunately, I get an "unspecified error" alert whenever I select a file. Can anyone help explain why this should be the case. Thanks Gary
3
15007
by: Murasama | last post by:
Hi there, Im trying a simple file IO operation in Visual Studio .NET 2003 and it can't seem to open the file. If I run the exe in the debug directory it works fine but if I click the start button (blue arrow) then it fails to open the file. any ideas? source:
6
5176
by: Charles Morrall | last post by:
I have no experience with DB2 as such, but I've been tasked with configuring backup of a server running DB2 v8 on Windows Server 2003. I do have some experience with backups in general though. The backup software I'll be using is Backup Exec 10, but Backup Exec doesn't have a specific agent for DB2, as it does for SQL and Oracle. The supplier...
2
3271
by: nissiml | last post by:
hi, i'm trying to open a asp.net web page that list files from a Windows application like winword and select a file from it . what do i have to do to make it happen, is it simple ? Thanks in Advance.
2
6119
by: Mattbooty | last post by:
Hello, Not sure if anyone else has seen this bug, but I have a form where the entire form is covered with a picturebox. The picturebox has a mouseup event. I also have an open file dialog for loading images into the picturebox. If you double click the file you want to open in the open file dialog, it somehow interperets one of the clicks...
2
12589
by: agphoto | last post by:
There is big or problem in open file in read and write mode.. $file = "data.txt"; $fp = fopen($file,"w+"); $line = fgets($fp,"120"); // i need only 1st line to read and upto 120 bytes echo $line; fclose($fp); coding is not problem, The problem is file modifier as mention in PHP
4
6448
by: DyslexicAnaboko | last post by:
Hello, I have a module that is part of larger project that is giving me trouble, so I setup an example. Brief ===== I simply want to open a text file and make the contents avaliable through stdin that way a bourne shell script I wrote will execute
5
11183
by: Ryan Liu | last post by:
Hi, Both way works, I'd just ask some experts which way is better? My application creates a log file daily. Now each time when I write a log, I will open the file and append to the end. Ocz, if the file is not exist(e.g. another day), it will creates the file first.
18
14593
by: Coffee Pot | last post by:
Thanks for any advice. ~ CP
0
7385
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7642
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7796
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5950
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5316
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3432
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1861
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.