A
Alec MacLean
Hi,
I've created a small application for our company extranet (staff bulletins)
that outputs a list of links to PDF's that are stored in a SQL table. The
user clicks a link and the PDF is loaded into a new browser window.
This works as expected on the test PC (using forms authentication, but no
SSL) using IE. It also works as expected on the production server when
using FireFox. The production server environment is using forms
authentication and SSL.
However the PDF load fails when using IE as the browser to access the
production server (which my users/staff colleagues will be doing).
I have also tested it without using SSL or Forms authentication by putting
it on our public site on the production server.
This also means you can (temporarily) see the problem for yourself
at: www.copeohs.com/ebulletins/bulletins.aspx
The error seems to be generated by Adobe Reader rather than specifically IE,
but as the system works using FireFox, I am guessing it is the relationship
between IE and Adobe Reader that is the problem?
The Adobe Reader error message provided is:
"There was an error opening this document. This file is already open or in
use by another application."
I am using VB.NET 1.1 on IIS 6 (win 2003 svr).
Code snippet that outputs the PDF from the DB:
--------------------------------------------------------
'The required file ID comes from the querystring.
If Me.Request.IsAuthenticated Then
If Request.QueryString.Count <> 0 Then
'Get the (pdf) filename to display
Me.FileID = CInt(Request.QueryString("doc").ToString)
Dim ds As New DataSet
Dim PDFfileSize As Long
Dim db As Database = DatabaseFactory.CreateDatabase
Dim cmd As DBCommandWrapper =
db.GetStoredProcCommandWrapper("usp_Bulletin_Single_SELECT")
cmd.AddInParameter("@BID", DbType.Int32, Me.FileID)
Try
Me.lblErr.Visible = False
'Load the record (PDF file) into local dataset
db.LoadDataSet(cmd, ds, "theBulletin")
'Resize the byte array for file
PDFfileSize =
CLng(ds.Tables("theBulletin").Rows(0).Item("BFile").length)
Dim thePDF(CInt(PDFfileSize)) As Byte
'Put the PDf into the byte array
thePDF = ds.Tables("theBulletin").Rows(0).Item("BFile")
'Send the file to the output stream
Response.BufferOutput = True
'Try and ensure the browser always opens the file and doesn't just
prompt to "open/save".
Response.AddHeader("Content-Disposition", "inline")
'Set the output stream to the correct content type (PDF).
Response.ContentType = "application/pdf"
'Output the file
Response.BinaryWrite(thePDF)
thePDF = Nothing
Catch ex As Exception
Me.lblErr.Visible = True
Me.lblErr.Text = ex.Message.ToString
Finally
'Tidy memory
ds = Nothing
cmd = Nothing
db = Nothing
End Try
End If
Else
Response.Redirect("/logon/applist.aspx")
End If
I've created a small application for our company extranet (staff bulletins)
that outputs a list of links to PDF's that are stored in a SQL table. The
user clicks a link and the PDF is loaded into a new browser window.
This works as expected on the test PC (using forms authentication, but no
SSL) using IE. It also works as expected on the production server when
using FireFox. The production server environment is using forms
authentication and SSL.
However the PDF load fails when using IE as the browser to access the
production server (which my users/staff colleagues will be doing).
I have also tested it without using SSL or Forms authentication by putting
it on our public site on the production server.
This also means you can (temporarily) see the problem for yourself
at: www.copeohs.com/ebulletins/bulletins.aspx
The error seems to be generated by Adobe Reader rather than specifically IE,
but as the system works using FireFox, I am guessing it is the relationship
between IE and Adobe Reader that is the problem?
The Adobe Reader error message provided is:
"There was an error opening this document. This file is already open or in
use by another application."
I am using VB.NET 1.1 on IIS 6 (win 2003 svr).
Code snippet that outputs the PDF from the DB:
--------------------------------------------------------
'The required file ID comes from the querystring.
If Me.Request.IsAuthenticated Then
If Request.QueryString.Count <> 0 Then
'Get the (pdf) filename to display
Me.FileID = CInt(Request.QueryString("doc").ToString)
Dim ds As New DataSet
Dim PDFfileSize As Long
Dim db As Database = DatabaseFactory.CreateDatabase
Dim cmd As DBCommandWrapper =
db.GetStoredProcCommandWrapper("usp_Bulletin_Single_SELECT")
cmd.AddInParameter("@BID", DbType.Int32, Me.FileID)
Try
Me.lblErr.Visible = False
'Load the record (PDF file) into local dataset
db.LoadDataSet(cmd, ds, "theBulletin")
'Resize the byte array for file
PDFfileSize =
CLng(ds.Tables("theBulletin").Rows(0).Item("BFile").length)
Dim thePDF(CInt(PDFfileSize)) As Byte
'Put the PDf into the byte array
thePDF = ds.Tables("theBulletin").Rows(0).Item("BFile")
'Send the file to the output stream
Response.BufferOutput = True
'Try and ensure the browser always opens the file and doesn't just
prompt to "open/save".
Response.AddHeader("Content-Disposition", "inline")
'Set the output stream to the correct content type (PDF).
Response.ContentType = "application/pdf"
'Output the file
Response.BinaryWrite(thePDF)
thePDF = Nothing
Catch ex As Exception
Me.lblErr.Visible = True
Me.lblErr.Text = ex.Message.ToString
Finally
'Tidy memory
ds = Nothing
cmd = Nothing
db = Nothing
End Try
End If
Else
Response.Redirect("/logon/applist.aspx")
End If