Learn how to a build a cloud-first strategyRegister Now


How To view PDF Files in a browser using the filename(path) reference in Database ?

Posted on 2007-10-03
Medium Priority
Last Modified: 2010-04-23
Hi All,

I am working on project where I need to view PDF files in a browser and the file reference (path) of the pdf file is in MS SQL SERVER DB Table.

The table layout is as follows:

autokey      uncname      path      
1      \\servername\sharename      c:\files\0001.pdf      
2      \\servername\sharename      c:\files\0002.pdf      
3      \\servername\sharename      c:\files\0003.pdf      
4      \\servername\sharename      c:\files\0004.pdf      
5      \\servername\sharename      c:\files\0005.pdf      
autokeyid      field1      field2      field2

I need to load the 0001.pdf file in the browser and design 3 text boxes so that user can input data into those boxes and that will populate the respective files in table 2.Once that is done user can move onto the next file in the table which is 0002.pdf...and so on

Hope this makes sense.

Can somebody please guide me on this one?


Question by:matrix_aash
LVL 14

Expert Comment

by:Jai S
ID: 20004797
either you have to use FRAMES or open the PDF file separately...

keep your TEXT boxes in one frame and in teh second frame have the PDF displayed...
it is not possible to display the PDF and you controls in one single page without using frames...

have your textboxes and the link to hte pdf file in you web page...and when the user clicks the link the pdf can be opened up...

Author Comment

ID: 20004925
I want the pdf file and the text boxes on the same page and not separately as it defeats the object. How can i load the image from database, that is the bit which i am confused about. It is possible for you give me some code ?
LVL 21

Expert Comment

ID: 20005128
If you want the PDF to be viewed along with other parts of the page, you MUST use one of the following tags:

The object tag would look something like this:
<object data="data/test.pdf" type="application/pdf" width="300" height="200">
  alt : <a href="data/test.pdf">test.pdf</a>

But, there is a problem.   Since the object tag was used in classic ASP to load COM objects, you cannot do this:
  <object id='PDFObject' runat='server'...>
This is because the ASP processor would try to load the COM object on the server and not generate any client html.

Instead, use the <asp:Literal> control like this:
  <asp:Literal id='PDFView' runat='server OnPreRender="BuildObjectTag"' />

Then in the code behind:
  protected void BuildObjectTag(object sender, EventArgs e)

LVL 21

Accepted Solution

MogalManic earned 2000 total points
ID: 20005194
sorry, submitted by mistake:
Then in the code behind:
  protected void BuildObjectTag(object sender, EventArgs e)
        string PDFFileLocation="~/PDFS/PDFFile.pdf";
         string ClientPath = page.ResolveClientUrl(PDFFileLoctaion);
         PDFView.Text=string.format(@"<object data='{0}' type='application/pdf' width='300' height='200'>
  alt : <a href='{0}'>Link to {0}</a>
</object>", ClientPath);

NOTE:  The PDF MUST be located within the WEB directory subtree.  If the PDF cannnot be located within the WEB subtree then you need to create a ViewPDF.aspx and the PDFFileLocation would be something like this:
   string PDFFileLocation="~/ViewPDF.aspx?FileName=PDFFile.pdf";
ViewPDF.aspx would then read the PDF file and write it to the Response and set the content type to 'application/pdf'

Expert Comment

ID: 20237779
Forced accept.

EE Admin

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question