Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 19th, 2006, 07:35 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Opening PDF files

Hello again!

Can someone tell me how can I open a PDF wich I store the path in a Access DB? I'm working with VB in .NET 1.1 .

Thanx in advance.

  #2 (permalink)  
Old October 19th, 2006, 08:51 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

If you have the path in a DB just use a standard A HREF to link to the file and it will open in IE. If you have the file actually stored in the DB you would do something like this:

        With Page.Response
            .Clear()
            .ContentType = "application/pdf"
            .OutputStream.Write([byteArray], 0, [byteArrayLength])
            .End()
        End With

hth


-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
  #3 (permalink)  
Old October 19th, 2006, 09:04 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx for the quick answer, dparsons.

But if I want to get the PDF from a certsin ID, would that work in the same way? Like using in:

...file.aspx?ID=n

or even:

RowView("ID").ToString()

Otherwise I will have to recode...

(hope u undestand my explaining)

  #4 (permalink)  
Old October 19th, 2006, 09:23 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

On your file.aspx page just do:

SELECT path FROM table WHERE id= Request.QueryString("id")

And then redirect to the path that is returned form the query.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
  #5 (permalink)  
Old October 19th, 2006, 09:42 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK. I'm getting somewhere...

I've added the
SELECT path FROM table WHERE id= Request.QueryString("id")

parts. I also added this on Page_Load:

   Response.ClearContent()
   Response.ClearHeaders()
   Response.ContentType = "application/pdf" Response.WriteFile(Server.MapPath("pdf-file's-name"))
                     ----------------------------------------
   Response.Flush()
   Response.Close()

And now shall I change the underlined into:

Response.WriteFile(Server.MapPath("field-name"))

??

Please, be patient with me. I'm just starting.
  #6 (permalink)  
Old October 19th, 2006, 09:56 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

First be aware of this: http://support.microsoft.com/kb/812406

Then do this:

Dim strPath as string = Server.MapPath([path value from database])
Dim file as System.IO.FileInfo = New System.IO.FileInfo(strPath)

If file.Exists then
With Response
     .Clear()
     .AddHeader("Content-Disposition", "attachment; filename=" & file.Name)
     .AddHeader("Content-Length", file.Length.ToString())
     .ContentType = "application/pdf"
     .WriteFile(file.FullName)
     .End

End With
Else
//file doesnt exist
End If

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
  #7 (permalink)  
Old October 19th, 2006, 10:42 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

But that way (I guess) I have to open a specified PDF and I want to get the corresponding PDF for a certain ID.

Is this correct?

  #8 (permalink)  
Old October 19th, 2006, 11:25 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I understand that, you would pass the ID along the query string

file.aspx?id=n

then you would do

SELECT path from table where id=Request.querystring("id")

the value that is returned from that query is what you want to place in the

Dim strPath as string = Server.MapPath([path value from database])



-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
  #9 (permalink)  
Old October 20th, 2006, 03:18 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've tried with

Dim strPath as string = Server.MapPath([FIELD with path value from database])

and I got this:

Could not find a part of the path "c:\inetpub\wwwroot\[FIELD with path value from database]".

Any ideas?

  #10 (permalink)  
Old October 20th, 2006, 07:19 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

.... the [Field with path value from the database] needs to be the actual value of the path from your database.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature




Similar Threads
Thread Thread Starter Forum Replies Last Post
error while opening the pdf file jijish ASP.NET 2.0 Professional 3 November 23rd, 2007 10:07 AM
Opening a PDF from html page hp1502 Javascript 1 September 19th, 2007 02:15 AM
Opening of New Window to show a .pdf report Dilip Nagle General .NET 5 March 8th, 2007 01:25 AM
Error in Opening PDF File ctranjith General .NET 0 September 30th, 2005 04:53 AM
opening of pdf file viren_balaut Pro JSP 2 August 23rd, 2004 06:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.