473,320 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to open PDF file in ASP.Net

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 56473
mohq82
2
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.WebClient client = new System.Net.WebClient();
Byte[] buffer = client.DownloadData(path);

if (buffer != null)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
}

hope it helps.
Nov 26 '06 #2
abbaky
2
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.redirect("The PDF file path") in the code
Nov 27 '06 #3
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
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="PFDViewer.aspx.vb" Inherits="Project.PFDViewer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<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
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
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...
2
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...
3
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...
6
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...
2
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...
2
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...
2
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...
4
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...
5
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....
18
by: Coffee Pot | last post by:
Thanks for any advice. ~ CP
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.