 |
| 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
|
|
|
|

October 19th, 2006, 07:35 AM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

October 19th, 2006, 08:51 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
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
|
|

October 19th, 2006, 09:04 AM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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)
|
|

October 19th, 2006, 09:23 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
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
|
|

October 19th, 2006, 09:42 AM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

October 19th, 2006, 09:56 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
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
|
|

October 19th, 2006, 10:42 AM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

October 19th, 2006, 11:25 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
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
|
|

October 20th, 2006, 03:18 AM
|
|
Authorized User
|
|
Join Date: May 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

October 20th, 2006, 07:19 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
.... 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
|
|
 |