Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Response.Redirect of pdf files

Status
Not open for further replies.

wendigt

Programmer
Dec 17, 2002
7
US
Help! I need to do a redirect to pdf files. The web browser seems to redirect to the server, but the page is not loaded. It only loads upon refresh. I've tried the following:

Response.ContentType = "application/pdf"
Response.Redirect "
I've also seen examples and have been unsuccessful with ADODB.Stream objects.

Is this even possible? BTW, I'm NOT using .NET. I'm developing in ASP (VBScript).

ANY advice is greatly appreciated!

Thanks!
Wendi
 
<%
Dim Stream
Dim Contents
Dim FileName
FileName = &quot;c:\html.pdf&quot;

Response.ContentType = &quot;application/octet-stream&quot;
Response.AddHeader &quot;content-disposition&quot;, &quot;attachment; filename=&quot; & FileName
Set Stream = server.CreateObject(&quot;ADODB.Stream&quot;)
Stream.Open
Stream.LoadFromFile Server.MapPath(FileName)
Contents = Stream.ReadText
Response.BinaryWrite Contents
Stream.Close
Set Stream = Nothing
%>
www.vzio.com
ASP WEB DEVELOPMENT



 
If you mean response.redirect then no, the above code i posted, forces a download... so if you wanted to download pdf, or and asp file, it will show the save dialog box. www.vzio.com
ASP WEB DEVELOPMENT



 
Right, I want to show pdf, not download it. An important note also is that the pdf resides on another server, not locally on disk. I've also tried the code at bottom of this post, but get error:

&quot;The script reported following error: File could not be opened. (error number 0x800A0BBA hex)

In file /webformresultdownloadECR.asp

on line 101, position 1 :


objStream.LoadFromFile FilePath&quot;



Here is the code:

strRedirect = &quot;
SendStreamToBrowser LoadStream (Server.MapPath(strRedirect)), strRedirect, False, True


Function LoadStream(FilePath)
Dim objStream

Set objStream = Server.CreateObject(&quot;ADODB.Stream&quot;)

objStream.Type = 1
objStream.Open

objStream.LoadFromFile FilePath
LoadStream = objStream.Read

objStream.Close
Set objStream = Nothing
End Function


sub SendStreamToBrowser(FileStream, FileName, ContentType, IsInline)
Dim FileExt, FileSize

on error resume next

Response.Clear

FileExt = mid(FileExt, instrrev(FileName,&quot;.&quot;) + 1)
FileSize = Ubound(FileStream) + 1

Response.AddHeader &quot;Connection&quot;, &quot;keep-alive&quot;
Response.AddHeader &quot;Content-Length&quot;, FileSize

If IsInline = True then
Response.AddHeader &quot;Content-Disposition&quot;,&quot;inline; filename=&quot; & FileName
Else
Response.AddHeader &quot;Content-Disposition&quot;,&quot;attachment; filename=&quot;&quot;&quot; & FileName & &quot;&quot;&quot;&quot;
End If

select case ContentType
case false
Response.ContentType = &quot;application/octet-stream&quot;
Response.Charset = &quot;UTF-8&quot;

case else
Response.ContentType = ContentType
end select

Response.BinaryWrite(FileStream)
Response.Flush
end sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top