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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stream PDF inline or close referring browser window

Status
Not open for further replies.

beckybear3

Programmer
Apr 27, 2006
2
US
I am a new programmer to .NET and I inherited an application that contains an aspx page that retrieves a Word document and streams it to the browser using the Response object (BinaryWrite). In the header, content-disposition is specified as inline and it opens the Word document in the browser with no problems.

I tried to extend this to also do PDF documents. The problem is, when the PDF document is streamed, it opens in a new Acrobat window (not inline, as specified in the content-disposition). Then I am left with a blank browser window that does nothing.

So I'd like to know either how to get the PDF document to display in the current browser window, or how to close the referring browser window once Acrobat is opened. I know that javascript can be used to close the window when attached to something in the user interface (button, link, etc), but I'm not sure how to do it without user intervention.

The aspx page just consists of Page_Load that does the following:

Code:
Response.Clear()
Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "Application/pdf"
Response.AddHeader("content-disposition", "inline; filename=comments.pdf")
            
Dim sr As System.IO.StreamReader
Try
  <code to get PDF path>
  sr = New System.IO.StreamReader(path)
  Dim ll As Long = sr.BaseStream.Length
  Dim re(ll) As Byte ''
  For i As Long = 0 To ll - 1
     re(i) = CType(sr.BaseStream.ReadByte(), Byte)
  Next
  Response.BinaryWrite(re)
  Response.End()
Catch ex As Exception
  Me.Response.Write(ex.ToString)
Finally
  sr.Close()
End Try

Thanks in advance for your help.
 
As far as I know, you don't have any control over this. The client can decide what to do with each file type regardless of what you suggest.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top